Permalink
Browse files

Merge branch 'master' of https://github.com/kuwabarahiroshi/zf2

  • Loading branch information...
2 parents ef90275 + d2cfcce commit b5f1a443e79ce658a843afcdda6028704e90cd74 @weierophinney weierophinney committed Sep 4, 2012
Showing with 16 additions and 1 deletion.
  1. +1 −1 library/Zend/Http/Response.php
  2. +15 −0 tests/ZendTest/Http/ResponseTest.php
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');

0 comments on commit b5f1a44

Please sign in to comment.