New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not assume CONTENT_TYPE is available, fall back to CakeResponse::type() #1661
Conversation
Could you please add a test for this and do you have an example of a server that doesn't include |
@@ -518,6 +518,9 @@ public function requestedWith($type = null) { | |||
} | |||
|
|||
list($contentType) = explode(';', env('CONTENT_TYPE')); | |||
if (is_null($contentType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$contentType === null
please.
When is content type missing? |
cli-server does not have CONTENT_TYPE on POST, instead it can be found in HTTP_CONTENT_TYPE. I'll see if I can drum up a test. |
Interesting. The CLI server continues to be a fountain of strange :) |
@@ -518,6 +518,9 @@ public function requestedWith($type = null) { | |||
} | |||
|
|||
list($contentType) = explode(';', env('CONTENT_TYPE')); | |||
if ($contentType === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explode() always returns an array of strings, so list() will most likely never be able to assign $contentType to null. Tests should proof that if ($contentType === '') {}
might be required here.
So the reason that CONTENT_TYPE is not available is because it is a CGI/1.1 requirement and as far as I can tell CLI PHP executables are built without CGI. Both Apache and FPM/FastCGI servers have a GATEWAY_INTERFACE of CGI/1.1. |
Could you squash all those commits into one please? Then we can merge them. Looks good to me. 👍 |
In some server environments notably the CLI server, _SERVER['CONTENT_TYPE'] is not available. In these cases, fall back to the HTTP_CONTENT_TYPE header. Refs #GH-1661
Squashed and merged in b1ea2d3 Thanks 👍 |
Not all servers will provide a CONTENT_TYPE environment variable.
In such a situation, the user is required to decode POST data explicitly with CakeRequest::input().
This patch falls back to CakeResponse::type() to determine the content type when the existing check provides null.