Skip to content

Commit

Permalink
Do not drain on HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Jun 30, 2016
1 parent 1fa6184 commit 1af7d30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Handler/StreamHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ private function createResponse(
}
}

if ($sink !== $stream) {
// Do not drain when the request is a HEAD request because they have
// no body.
if ($sink !== $stream && strcasecmp('HEAD', $request->getMethod())) {
$this->drain(
$stream,
$sink,
Expand Down
19 changes: 19 additions & 0 deletions tests/Handler/StreamHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ public function testDrainsResponseAndReadsOnlyContentLengthBytes()
fclose($stream);
}

public function testDoesNotDrainWhenHeadRequest()
{
Server::flush();
// Say the content-length is 8, but return no response.
Server::enqueue([
new Response(200, [
'Foo' => 'Bar',
'Content-Length' => 8,
], '')
]);
$handler = new StreamHandler();
$request = new Request('HEAD', Server::$url);
$response = $handler($request, [])->wait();
$body = $response->getBody();
$stream = $body->detach();
$this->assertEquals('', stream_get_contents($stream));
fclose($stream);
}

public function testAutomaticallyDecompressGzip()
{
Server::flush();
Expand Down

0 comments on commit 1af7d30

Please sign in to comment.