Skip to content

Commit

Permalink
Send correct status code regardless of location header
Browse files Browse the repository at this point in the history
PHP thinks it's clever, but it isn't. Fixes slimphp#1730.
  • Loading branch information
kelunik committed Sep 28, 2017
1 parent 403b798 commit a2c93ac
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Slim/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,20 +388,23 @@ public function respond(ResponseInterface $response)
{
// Send response
if (!headers_sent()) {
// Headers
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}

// Set the status _after_ the headers, because of PHP's "helpful" behavior with location headers.
// See https://github.com/slimphp/Slim/issues/1730

// Status
header(sprintf(
'HTTP/%s %s %s',
$response->getProtocolVersion(),
$response->getStatusCode(),
$response->getReasonPhrase()
));

// Headers
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
}

// Body
Expand Down

0 comments on commit a2c93ac

Please # to comment.