Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modified status line parser regexp.

HTTP response should accept status line with zero length reasen phrase.
  • Loading branch information...
commit d2cfccec0a376f457cf1ab67e598183d62f280f0 1 parent 3a4cee6
@kuwabarahiroshi kuwabarahiroshi authored
View
2  library/Zend/Http/Response.php
@@ -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(
View
15 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');
Please sign in to comment.
Something went wrong with that request. Please try again.