Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Response.php
Expand Up @@ -180,7 +180,7 @@ public static function fromString($string)

$response = new static();

$regex = '/^HTTP\/(?P<version>1\.[01]) (?P<status>\d{3})(?:[ ]+(?P<reason>.+))?$/';
$regex = '/^HTTP\/(?P<version>1\.[01]) (?P<status>\d{3})(?:[ ]+(?P<reason>.*))?$/';
$matches = array();
if (!preg_match($regex, $firstLine, $matches)) {
throw new Exception\InvalidArgumentException(
Expand Down
15 changes: 15 additions & 0 deletions test/ResponseTest.php
Expand Up @@ -73,6 +73,21 @@ public function testResponseEndsAtStatusCode()
$this->assertEquals('Foo Bar', $response->getContent());
}

public function testResponseHasZeroLengthReasonPhrase()
{
// Space after status code is mandatory,
// though, reason phrase can be empty.
// @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
$string = 'HTTP/1.0 200 ' . "\r\n\r\n" . 'Foo Bar';

$response = Response::fromString($string);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Foo Bar', $response->getContent());

// Reason phrase would fallback to default reason phrase.
$this->assertEquals('OK', $response->getReasonPhrase());
}

public function testGzipResponse ()
{
$response_text = file_get_contents(__DIR__ . '/_files/response_gzip');
Expand Down

0 comments on commit 2756031

Please sign in to comment.