Skip to content
Permalink
Browse files

Don't emit response bodies for 204 and 304 responses.

This makes the behavior of the PSR7 stack consistent with how CakePHP
has historically behaved.
  • Loading branch information...
markstory committed Nov 21, 2016
1 parent 09b3f0f commit 5ec7c0e1e4781e911f66cd561344153adbaffeb3
Showing with 27 additions and 0 deletions.
  1. +3 −0 src/Http/ResponseEmitter.php
  2. +24 −0 tests/TestCase/Http/ResponseEmitterTest.php
@@ -76,6 +76,9 @@ public function emit(ResponseInterface $response, $maxBufferLength = 8192)
*/
protected function emitBody(ResponseInterface $response, $maxBufferLength)
{
if (in_array($response->getStatusCode(), [204, 304])) {
return;
}
$body = $response->getBody();
if (!$body->isSeekable()) {
@@ -63,6 +63,30 @@ public function testEmitResponseSimple()
$this->assertEquals($expected, $GLOBALS['mockedHeaders']);
}
/**
* Test emitting a no-content response
*
* @return void
*/
public function testEmitNoContentResponse()
{
$response = (new Response())
->withHeader('X-testing', 'value')
->withStatus(204);
$response->getBody()->write('It worked');
ob_start();
$this->emitter->emit($response);
$out = ob_get_clean();
$this->assertEquals('', $out);
$expected = [
'HTTP/1.1 204 No Content',
'X-testing: value',
];
$this->assertEquals($expected, $GLOBALS['mockedHeaders']);
}
/**
* Test emitting responses with cookies
*

0 comments on commit 5ec7c0e

Please sign in to comment.
You can’t perform that action at this time.