From d5d5a3c723484e8cd8ac3b3cdab3b0ab81ddb461 Mon Sep 17 00:00:00 2001 From: Simon Bennett Date: Thu, 3 Mar 2022 13:12:26 +0000 Subject: [PATCH] Head request unit test --- tests/Io/StreamingServerTest.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Io/StreamingServerTest.php b/tests/Io/StreamingServerTest.php index 59cfd118..45729f2b 100644 --- a/tests/Io/StreamingServerTest.php +++ b/tests/Io/StreamingServerTest.php @@ -1426,6 +1426,38 @@ function ($data) use (&$buffer) { $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); } + public function testResponseContainsExplicitContentLengthHeaderForHeadRequests() + { + $server = new StreamingServer(Loop::get(), function (ServerRequestInterface $request) { + return new Response( + 200, + array('Content-Length' => 3), + '' + ); + }); + + $buffer = ''; + $this->connection + ->expects($this->any()) + ->method('write') + ->will( + $this->returnCallback( + function ($data) use (&$buffer) { + $buffer .= $data; + } + ) + ); + + $server->listen($this->socket); + $this->socket->emit('connection', array($this->connection)); + + $data = "HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n"; + $this->connection->emit('data', array($data)); + + $this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer); + $this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer); + } + public function testResponseContainsNoResponseBodyForNotModifiedStatus() { $server = new StreamingServer(Loop::get(), function (ServerRequestInterface $request) {