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

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static function fromString($string)
180180

181181
$response = new static();
182182

183-
$regex = '/^HTTP\/(?P<version>1\.[01]) (?P<status>\d{3})(?:[ ]+(?P<reason>.+))?$/';
183+
$regex = '/^HTTP\/(?P<version>1\.[01]) (?P<status>\d{3})(?:[ ]+(?P<reason>.*))?$/';
184184
$matches = array();
185185
if (!preg_match($regex, $firstLine, $matches)) {
186186
throw new Exception\InvalidArgumentException(

test/ResponseTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ public function testResponseEndsAtStatusCode()
7373
$this->assertEquals('Foo Bar', $response->getContent());
7474
}
7575

76+
public function testResponseHasZeroLengthReasonPhrase()
77+
{
78+
// Space after status code is mandatory,
79+
// though, reason phrase can be empty.
80+
// @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
81+
$string = 'HTTP/1.0 200 ' . "\r\n\r\n" . 'Foo Bar';
82+
83+
$response = Response::fromString($string);
84+
$this->assertEquals(200, $response->getStatusCode());
85+
$this->assertEquals('Foo Bar', $response->getContent());
86+
87+
// Reason phrase would fallback to default reason phrase.
88+
$this->assertEquals('OK', $response->getReasonPhrase());
89+
}
90+
7691
public function testGzipResponse ()
7792
{
7893
$response_text = file_get_contents(__DIR__ . '/_files/response_gzip');

0 commit comments

Comments
 (0)