Skip to content

Commit 5d93556

Browse files
authored
Merge pull request #23 from magento-mpi/MC-18944
MC-18944: ZendClient breaks when receiving an HTTP/2 response
2 parents 8221062 + 33014a0 commit 5d93556

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

library/Zend/Http/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function __construct($code, array $headers, $body = null, $version = '1.1
182182
$this->body = $body;
183183

184184
// Set the HTTP version
185-
if (! preg_match('|^\d\.\d$|', $version)) {
185+
if (! preg_match('|^\d+(?:\.\d+)?$|', $version)) {
186186
#require_once 'Zend/Http/Exception.php';
187187
throw new Zend_Http_Exception("Invalid HTTP response version: $version");
188188
}
@@ -514,7 +514,7 @@ public static function extractHeaders($response_str)
514514
$last_header = null;
515515

516516
foreach($lines as $index => $line) {
517-
if ($index === 0 && preg_match('#^HTTP/\d+(?:\.\d+) [1-5]\d+#', $line)) {
517+
if ($index === 0 && preg_match('#^HTTP/\d+(?:\.\d+)? [1-5]\d+#', $line)) {
518518
// Status line; ignore
519519
continue;
520520
}

tests/Zend/Http/ResponseTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,39 @@ public function testExtractHeadersShouldAllowHeadersWithMissingValues()
451451
$this->assertArrayHasKey('imagetoolbar', $headers);
452452
$this->assertEmpty($headers['imagetoolbar']);
453453
}
454+
455+
/**
456+
* Test that parsing HTTP2 response works.
457+
*/
458+
public function testExtractHeadersShouldWorkWithHTTTP2()
459+
{
460+
$response = $this->readResponse('response_http_2');
461+
$headers = Zend_Http_Response::extractHeaders($response);
462+
463+
$this->assertArrayHasKey('connection', $headers);
464+
$this->assertEquals('Keep-Alive', $headers['connection']);
465+
}
466+
467+
/**
468+
* Tests that version is validated properly when passed to the constructor.
469+
*
470+
* @param string $version
471+
* @dataProvider constructorWithVersionDataProvider
472+
*/
473+
public function testConstructorWithVersion($version)
474+
{
475+
try {
476+
new Zend_Http_Response(200, array(), null, $version);
477+
} catch (Zend_Http_Exception $e) {
478+
$this->fail('Passing HTTP version ' . $version . ' generates an exception');
479+
}
480+
}
481+
482+
/**
483+
* @return array
484+
*/
485+
public function constructorWithVersionDataProvider()
486+
{
487+
return array('1.0', '1.1', '2', '11.11');
488+
}
454489
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
HTTP/2 200 OK
2+
Date: Wed, 05 Aug 2015 16:52:40 GMT
3+
Server: Apache
4+
Content-Length: 0
5+
Keep-Alive: timeout=15, max=100
6+
Connection: Keep-Alive
7+
Content-Type: text/html; charset=iso-8859-1
8+
9+

0 commit comments

Comments
 (0)