Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 0524493

Browse files
committed
Merge pull request #160 from xtreamwayz/hotfix/marshal-http2-protocol
Accept HTTP/2 protocol
2 parents a714e44 + d0beee7 commit 0524493

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/ServerRequestFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ private static function marshalProtocolVersion(array $server)
470470
return '1.1';
471471
}
472472

473-
if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*\.\d)$#', $server['SERVER_PROTOCOL'], $matches)) {
473+
if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
474474
throw new UnexpectedValueException(sprintf(
475475
'Unrecognized protocol version (%s)',
476476
$server['SERVER_PROTOCOL']

test/ServerRequestFactoryTest.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,6 @@ public function testNormalizeFilesReturnsOnlyActualFilesWhenOriginalFilesContain
454454
$this->assertCount(1, $normalizedFiles['fooFiles']);
455455
}
456456

457-
public function testMarshalProtocolVersionReturnsHttpVersion()
458-
{
459-
$method = new ReflectionMethod('Zend\Diactoros\ServerRequestFactory', 'marshalProtocolVersion');
460-
$method->setAccessible(true);
461-
$version = $method->invoke(null, ['SERVER_PROTOCOL' => 'HTTP/1.0']);
462-
$this->assertEquals('1.0', $version);
463-
}
464-
465457
public function testMarshalProtocolVersionRisesExceptionIfVersionIsNotRecognized()
466458
{
467459
$method = new ReflectionMethod('Zend\Diactoros\ServerRequestFactory', 'marshalProtocolVersion');
@@ -477,4 +469,24 @@ public function testMarshalProtocolReturnsDefaultValueIfHeaderIsNotPresent()
477469
$version = $method->invoke(null, []);
478470
$this->assertEquals('1.1', $version);
479471
}
472+
473+
/**
474+
* @dataProvider marshalProtocolVersionProvider
475+
*/
476+
public function testMarshalProtocolVersionReturnsHttpVersions($protocol, $expected)
477+
{
478+
$method = new ReflectionMethod('Zend\Diactoros\ServerRequestFactory', 'marshalProtocolVersion');
479+
$method->setAccessible(true);
480+
$version = $method->invoke(null, ['SERVER_PROTOCOL' => $protocol]);
481+
$this->assertEquals($expected, $version);
482+
}
483+
484+
public function marshalProtocolVersionProvider()
485+
{
486+
return [
487+
'HTTP/1.0' => ['HTTP/1.0', '1.0'],
488+
'HTTP/1.1' => ['HTTP/1.1', '1.1'],
489+
'HTTP/2' => ['HTTP/2', '2'],
490+
];
491+
}
480492
}

0 commit comments

Comments
 (0)