Skip to content

Support legacy HTTP servers that use only LF instead of CRLF #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2018
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy