Skip to content

Commit

Permalink
Merge pull request #3139 from adoy/fix-1739
Browse files Browse the repository at this point in the history
Fixed #1730 (reintroduced in 4.x)
  • Loading branch information
l0gicgate authored Jan 13, 2022
2 parents 2b74627 + 85cf515 commit 6aa522d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit 6aa522d

Please sign in to comment.