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 #1730.
  • Loading branch information
kelunik authored and akrabat committed Nov 3, 2017
1 parent d1c5b02 commit 0dab1d1
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 @@ -664,20 +664,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 0dab1d1

Please sign in to comment.