From 63c223591e05d511e50ad9a715c0dd3532b5f206 Mon Sep 17 00:00:00 2001 From: mapogolions Date: Wed, 14 Aug 2019 02:51:17 +0500 Subject: [PATCH 1/2] Reproduce incorrect header search in stack --- tests/ResponseEmitterTest.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/ResponseEmitterTest.php b/tests/ResponseEmitterTest.php index c30de4f00..32e8daff0 100644 --- a/tests/ResponseEmitterTest.php +++ b/tests/ResponseEmitterTest.php @@ -40,16 +40,40 @@ public function testRespond() public function testRespondNoContent() { - $response = $this->createResponse(); + $response = $this + ->createResponse() + ->withHeader('Content-Type', 'text/html') + ->withHeader('Content-Length', '4096') + ->withHeader('Cache-Control', 'no-cache'); $responseEmitter = new ResponseEmitter(); $responseEmitter->emit($response); - $this->assertEquals(false, HeaderStack::has('Content-Type')); - $this->assertEquals(false, HeaderStack::has('Content-Length')); + $this->assertFalse(HeaderStack::has('Content-Type')); + $this->assertFalse(HeaderStack::has('Content-Length')); + $this->assertTrue(HeaderStack::has('Cache-Control')); $this->expectOutputString(''); } + public function testNonEmptyResponse() + { + $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(); From 383627be24d1cd14cefe8e18e2738be7e243afb5 Mon Sep 17 00:00:00 2001 From: mapogolions Date: Wed, 14 Aug 2019 02:52:47 +0500 Subject: [PATCH 2/2] Fix incorrect header search in stack --- tests/Assets/HeaderStack.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Assets/HeaderStack.php b/tests/Assets/HeaderStack.php index 7dd4a7e15..ba93dd26f 100644 --- a/tests/Assets/HeaderStack.php +++ b/tests/Assets/HeaderStack.php @@ -79,11 +79,11 @@ public static function stack() public static function has($header) { foreach (self::$data as $item) { - if ($item['header'] === $header) { + $components = explode(':', $item['header']); + if (trim($components[0]) === $header) { return true; } } - return false; } }