Problem
I'm having an issue trying to send a HEAD request to a D8 installation to verify the existence of a particular entity. A HEAD request to an existing (newly created) Node will always fail with the following 500 error:
LogicException: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? in Symfony\Component\HttpKernel\HttpKernel->handleRaw() (line 157 of /var/www/drupal/vendor/symfony/http-kernel/HttpKernel.php).
Oddly, after sending a single GET request to the same endpoint all subsequent HEAD requests are successful. The handleRaw method in the error doesn't seem helpful as it only shows that a request object is not received.
How to reproduce
I was using HttpClient in a custom module, but the easiest way to reproduce is using Postman:
1. Create a new node setting Authentication, Accept, Content-Type, and CSRF token headers:POST: http://drupalvm.dev/entity/node?_format=hal_json
With the following body:
{"type": [{"target_id": "article"
}],"title": [{"value": "testing head request to test entity exists","lang": "en"
}],"status": [{"value": 1,"lang": "en"
}],"promote": [{"value": 1,"lang": "en"
}],"sticky": [{"value": 0,"lang": "en"
}],"body": [{"value": "this is the body < \/p>\r\n","format": "basic_html","summary": "","lang": "en"
}]
}
Returns 201 Created
2. Send a HEAD request to that new node (in this case nid 46):HEAD http://drupalvm2.dev/node/46?_format=hal_json
Returns 500 server error
3. Send a GET request to that new node:GET http://drupalvm2.dev/node/46?_format=hal_json
Returns 200 OK
4. Now repeat number 2. This and all subsequent HEAD requests are now successful with a 200 status.