Skip to content

Commit

Permalink
Head request unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonbennett committed Mar 3, 2022
1 parent 04d5e75 commit d5d5a3c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Io/StreamingServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d5d5a3c

Please sign in to comment.