Skip to content

Commit

Permalink
Merge pull request #23 from magento-mpi/MC-18944
Browse files Browse the repository at this point in the history
MC-18944: ZendClient breaks when receiving an HTTP/2 response
  • Loading branch information
viktym committed Aug 13, 2019
2 parents 8221062 + 33014a0 commit 5d93556
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Zend/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function __construct($code, array $headers, $body = null, $version = '1.1
$this->body = $body;

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

foreach($lines as $index => $line) {
if ($index === 0 && preg_match('#^HTTP/\d+(?:\.\d+) [1-5]\d+#', $line)) {
if ($index === 0 && preg_match('#^HTTP/\d+(?:\.\d+)? [1-5]\d+#', $line)) {
// Status line; ignore
continue;
}
Expand Down
35 changes: 35 additions & 0 deletions tests/Zend/Http/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,39 @@ public function testExtractHeadersShouldAllowHeadersWithMissingValues()
$this->assertArrayHasKey('imagetoolbar', $headers);
$this->assertEmpty($headers['imagetoolbar']);
}

/**
* Test that parsing HTTP2 response works.
*/
public function testExtractHeadersShouldWorkWithHTTTP2()
{
$response = $this->readResponse('response_http_2');
$headers = Zend_Http_Response::extractHeaders($response);

$this->assertArrayHasKey('connection', $headers);
$this->assertEquals('Keep-Alive', $headers['connection']);
}

/**
* Tests that version is validated properly when passed to the constructor.
*
* @param string $version
* @dataProvider constructorWithVersionDataProvider
*/
public function testConstructorWithVersion($version)
{
try {
new Zend_Http_Response(200, array(), null, $version);
} catch (Zend_Http_Exception $e) {
$this->fail('Passing HTTP version ' . $version . ' generates an exception');
}
}

/**
* @return array
*/
public function constructorWithVersionDataProvider()
{
return array('1.0', '1.1', '2', '11.11');
}
}
9 changes: 9 additions & 0 deletions tests/Zend/Http/_files/response_http_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/2 200 OK
Date: Wed, 05 Aug 2015 16:52:40 GMT
Server: Apache
Content-Length: 0
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1


0 comments on commit 5d93556

Please sign in to comment.