Skip to content

Commit d5d5a3c

Browse files
Head request unit test
1 parent 04d5e75 commit d5d5a3c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/Io/StreamingServerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,38 @@ function ($data) use (&$buffer) {
14261426
$this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer);
14271427
}
14281428

1429+
public function testResponseContainsExplicitContentLengthHeaderForHeadRequests()
1430+
{
1431+
$server = new StreamingServer(Loop::get(), function (ServerRequestInterface $request) {
1432+
return new Response(
1433+
200,
1434+
array('Content-Length' => 3),
1435+
''
1436+
);
1437+
});
1438+
1439+
$buffer = '';
1440+
$this->connection
1441+
->expects($this->any())
1442+
->method('write')
1443+
->will(
1444+
$this->returnCallback(
1445+
function ($data) use (&$buffer) {
1446+
$buffer .= $data;
1447+
}
1448+
)
1449+
);
1450+
1451+
$server->listen($this->socket);
1452+
$this->socket->emit('connection', array($this->connection));
1453+
1454+
$data = "HEAD / HTTP/1.1\r\nHost: localhost\r\n\r\n";
1455+
$this->connection->emit('data', array($data));
1456+
1457+
$this->assertContainsString("HTTP/1.1 200 OK\r\n", $buffer);
1458+
$this->assertContainsString("\r\nContent-Length: 3\r\n", $buffer);
1459+
}
1460+
14291461
public function testResponseContainsNoResponseBodyForNotModifiedStatus()
14301462
{
14311463
$server = new StreamingServer(Loop::get(), function (ServerRequestInterface $request) {

0 commit comments

Comments
 (0)