zendframework / zend-http

Http component from Zend Framework
BSD 3-Clause "New" or "Revised" License
134 stars 85 forks source link

parseStatusLine throws exception for HTTP/2 Response #172

Closed av3 closed 5 years ago

av3 commented 5 years ago

I want to write a small function to test, if a specific Host supports HTTP/2 - using zend-http and the CURL adapter with the CURL_HTTP_VERSION_2_0 option. But this ends in an exception:

Zend \ Http \ Exception \ InvalidArgumentException A valid response status line was not found in the provided string

It seems that the regex within parseStatusLine (https://github.com/zendframework/zend-http/blob/master/src/Response.php#L252) doesn't match with the HTTP/2 response.

Code to reproduce the issue (incomplete)

$client = new \Zend\Http\Client\Client();
$options = [
    'adapter'      => \Zend\Http\Client\Adapter\Curl::class,
    'curloptions'  => [
    // ...
        CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_2_0,
    ],
];
$client->setOptions($options);

// ...

$response = $client->send();

Test case for this:

    public function testResponseFactoryFromStringCreatesValidHTTP2Response()
    {
        $string = 'HTTP/2.0 200 OK' . "\r\n\r\n" . 'Foo Bar';
        $response = \Zend\Http\Response::fromString($string);
        $this->assertEquals(200, $response->getStatusCode());
        $this->assertEquals('Foo Bar', $response->getContent());
    }