Skip to content
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

make sure HEAD requests do not return a body #2576

Merged
merged 6 commits into from Feb 8, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions Slim/App.php
Expand Up @@ -614,7 +614,8 @@ protected function finalize(ResponseInterface $response)
// stop PHP sending a Content-Type automatically
ini_set('default_mimetype', '');

if ($this->isEmptyResponse($response)) {
$request = $this->container->get('request');
if ($this->isEmptyResponse($response) && $request->getMethod() !== 'HEAD') {
lordrhodos marked this conversation as resolved.
Show resolved Hide resolved
return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
}

Expand All @@ -635,7 +636,8 @@ protected function finalize(ResponseInterface $response)
}

/**
* Helper method, which returns true if the provided response must not output a body and false
* Helper method, which returns true if the request is a HEAD request or
* if the provided response must not output a body and false
* if the response could have a body.
*
* @see https://tools.ietf.org/html/rfc7231
Expand All @@ -645,6 +647,11 @@ protected function finalize(ResponseInterface $response)
*/
protected function isEmptyResponse(ResponseInterface $response)
{
$request = $this->container->get('request');
if ($request->getMethod() === 'HEAD') {
lordrhodos marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

if (method_exists($response, 'isEmpty')) {
return $response->isEmpty();
}
Expand Down