diff --git a/library/Zend/Http/Response.php b/library/Zend/Http/Response.php index 2de4dda1902..9ab7636af91 100644 --- a/library/Zend/Http/Response.php +++ b/library/Zend/Http/Response.php @@ -180,7 +180,7 @@ public static function fromString($string) $response = new static(); - $regex = '/^HTTP\/(?P1\.[01]) (?P\d{3})(?:[ ]+(?P.+))?$/'; + $regex = '/^HTTP\/(?P1\.[01]) (?P\d{3})(?:[ ]+(?P.*))?$/'; $matches = array(); if (!preg_match($regex, $firstLine, $matches)) { throw new Exception\InvalidArgumentException( diff --git a/tests/ZendTest/Http/ResponseTest.php b/tests/ZendTest/Http/ResponseTest.php index 651a2cc4ea3..f11527778d2 100644 --- a/tests/ZendTest/Http/ResponseTest.php +++ b/tests/ZendTest/Http/ResponseTest.php @@ -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');