Skip to content

Commit

Permalink
Accept HTTP/2 protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
geerteltink committed Mar 17, 2016
1 parent a714e44 commit d0beee7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ServerRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private static function marshalProtocolVersion(array $server)
return '1.1';
}

if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*\.\d)$#', $server['SERVER_PROTOCOL'], $matches)) {
if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
throw new UnexpectedValueException(sprintf(
'Unrecognized protocol version (%s)',
$server['SERVER_PROTOCOL']
Expand Down
28 changes: 20 additions & 8 deletions test/ServerRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,6 @@ public function testNormalizeFilesReturnsOnlyActualFilesWhenOriginalFilesContain
$this->assertCount(1, $normalizedFiles['fooFiles']);
}

public function testMarshalProtocolVersionReturnsHttpVersion()
{
$method = new ReflectionMethod('Zend\Diactoros\ServerRequestFactory', 'marshalProtocolVersion');
$method->setAccessible(true);
$version = $method->invoke(null, ['SERVER_PROTOCOL' => 'HTTP/1.0']);
$this->assertEquals('1.0', $version);
}

public function testMarshalProtocolVersionRisesExceptionIfVersionIsNotRecognized()
{
$method = new ReflectionMethod('Zend\Diactoros\ServerRequestFactory', 'marshalProtocolVersion');
Expand All @@ -477,4 +469,24 @@ public function testMarshalProtocolReturnsDefaultValueIfHeaderIsNotPresent()
$version = $method->invoke(null, []);
$this->assertEquals('1.1', $version);
}

/**
* @dataProvider marshalProtocolVersionProvider
*/
public function testMarshalProtocolVersionReturnsHttpVersions($protocol, $expected)
{
$method = new ReflectionMethod('Zend\Diactoros\ServerRequestFactory', 'marshalProtocolVersion');
$method->setAccessible(true);
$version = $method->invoke(null, ['SERVER_PROTOCOL' => $protocol]);
$this->assertEquals($expected, $version);
}

public function marshalProtocolVersionProvider()
{
return [
'HTTP/1.0' => ['HTTP/1.0', '1.0'],
'HTTP/1.1' => ['HTTP/1.1', '1.1'],
'HTTP/2' => ['HTTP/2', '2'],
];
}
}

0 comments on commit d0beee7

Please sign in to comment.