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

ResponseEmitter: Don't remove Content-Type and Content-Length when body is empty #2925

Merged
merged 2 commits into from
Jan 30, 2020
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
5 changes: 0 additions & 5 deletions Slim/ResponseEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public function emit(ResponseInterface $response): void
{
$isEmpty = $this->isResponseEmpty($response);
if (headers_sent() === false) {
if ($isEmpty) {
$response = $response
->withoutHeader('Content-Type')
->withoutHeader('Content-Length');
}
$this->emitStatusLine($response);
$this->emitHeaders($response);
}
Expand Down
36 changes: 0 additions & 36 deletions tests/ResponseEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,6 @@ public function testRespond()
$this->expectOutputString('Hello');
}

public function testResposeWithNoContentSkipsContentTypeAndContentLength()
{
$response = $this
->createResponse()
->withHeader('Content-Type', 'text/html')
->withHeader('Content-Length', '4096')
->withHeader('Cache-Control', 'no-cache');

$responseEmitter = new ResponseEmitter();
$responseEmitter->emit($response);

$this->assertFalse(HeaderStack::has('Content-Type'));
$this->assertFalse(HeaderStack::has('Content-Length'));
$this->assertTrue(HeaderStack::has('Cache-Control'));
$this->expectOutputString('');
}

public function testNonEmptyResponseDoesNotSkipContentTypeAndContentLength()
{
$response = $this
->createResponse()
->withHeader('Content-Type', 'text/html')
->withHeader('Content-Length', '4096')
->withHeader('Cache-Control', 'no-cache');

$response->getBody()->write('foo');

$responseEmitter = new ResponseEmitter();
$responseEmitter->emit($response);

$this->assertTrue(HeaderStack::has('Content-Type'));
$this->assertTrue(HeaderStack::has('Content-Length'));
$this->assertTrue(HeaderStack::has('Cache-Control'));
$this->expectOutputString('foo');
}

public function testRespondWithPaddedStreamFilterOutput()
{
$availableFilter = stream_get_filters();
Expand Down