Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Slim/ResponseEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public function emit(ResponseInterface $response): void
{
$isEmpty = $this->isResponseEmpty($response);
if (headers_sent() === false) {
$this->emitStatusLine($response);
$this->emitHeaders($response);

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

$this->emitStatusLine($response);
}

if (!$isEmpty) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ResponseEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public function testResponseReplacesPreviouslySetHeaders()
$responseEmitter->emit($response);

$expectedStack = [
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
['header' => 'X-Foo: baz1', 'replace' => true, 'status_code' => null],
['header' => 'X-Foo: baz2', 'replace' => false, 'status_code' => null],
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
];

$this->assertSame($expectedStack, HeaderStack::stack());
Expand All @@ -162,9 +162,9 @@ public function testResponseDoesNotReplacePreviouslySetSetCookieHeaders()
$responseEmitter->emit($response);

$expectedStack = [
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
['header' => 'set-cOOkie: foo=bar', 'replace' => false, 'status_code' => null],
['header' => 'set-cOOkie: bar=baz', 'replace' => false, 'status_code' => null],
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
];

$this->assertSame($expectedStack, HeaderStack::stack());
Expand Down