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

Commit b1d5973

Browse files
committed
Merge branch 'hotfix/160'
Close #160
2 parents a714e44 + b35c2ad commit b1d5973

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 1.3.5 - TBD
5+
## 1.3.5 - 2016-03-17
66

77
### Added
88

@@ -18,7 +18,8 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#160](https://github.com/zendframework/zend-diactoros/pull/160) fixes HTTP
22+
protocol detection in the `ServerRequestFactory` to work correctly with HTTP/2.
2223

2324
## 1.3.4 - 2016-03-17
2425

src/ServerRequestFactory.php

+1-1
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

+20-8
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)