Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MC-18944: ZendClient breaks when receiving an HTTP/2 response #23

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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