Skip to content

Commit

Permalink
fix response code to support http2
Browse files Browse the repository at this point in the history
closes #60
  • Loading branch information
anlutro committed Nov 19, 2018
1 parent 17f3aca commit da458fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function parseHeaders(array $headers)

// find and set the HTTP status code and reason
$firstHeader = array_shift($headers);
if (!preg_match('/^HTTP\/\d\.\d [0-9]{3}/', $firstHeader)) {
if (!preg_match('/^HTTP\/\d(\.\d)? [0-9]{3}/', $firstHeader)) {
throw new \InvalidArgumentException('Invalid response header');
}
list(, $status) = explode(' ', $firstHeader, 2);
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public function parsesHttpResponseCodeCorrectly()
$this->assertEquals('302 Found', $r->statusText);
}

/** @test */
public function parsesHttp2ResponseCorrectly()
{
$r = $this->makeResponse('', 'HTTP/2 200 OK');
$this->assertEquals(200, $r->statusCode);
$this->assertEquals('200 OK', $r->statusText);
}

/** @test */
public function parsesHeaderStringCorrectly()
{
Expand Down

0 comments on commit da458fd

Please sign in to comment.