Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public function handleData($data)
{
$this->buffer .= $data;

if (false !== strpos($this->buffer, "\r\n\r\n")) {
// buffer until double CRLF (or double LF for compatibility with legacy servers)
if (false !== strpos($this->buffer, "\r\n\r\n") || false !== strpos($this->buffer, "\n\n")) {
try {
list($response, $bodyChunk) = $this->parseResponse($this->buffer);
} catch (\InvalidArgumentException $exception) {
Expand Down
23 changes: 23 additions & 0 deletions tests/FunctionalIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ public function testRequestToLocalhostEmitsSingleRemoteConnection()
$loop->run();
}

public function testRequestLegacyHttpServerWithOnlyLineFeedReturnsSuccessfulResponse()
{
$loop = Factory::create();

$server = new Server(0, $loop);
$server->on('connection', function (ConnectionInterface $conn) use ($server) {
$conn->end("HTTP/1.0 200 OK\n\nbody");
$server->close();
});

$client = new Client($loop);
$request = $client->request('GET', str_replace('tcp:', 'http:', $server->getAddress()));

$once = $this->expectCallableOnceWith('body');
$request->on('response', function (Response $response) use ($once) {
$response->on('data', $once);
});

$request->end();

$loop->run();
}

/** @group internet */
public function testSuccessfulResponseEmitsEnd()
{
Expand Down
11 changes: 11 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ protected function expectCallableOnce()
return $mock;
}

protected function expectCallableOnceWith($value)
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke')
->with($value);

return $mock;
}

protected function expectCallableNever()
{
$mock = $this->createCallableMock();
Expand Down