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

parseStatusLine throws exception for HTTP/2 Response #172

Closed
av3 opened this issue Feb 14, 2019 · 0 comments
Closed

parseStatusLine throws exception for HTTP/2 Response #172

av3 opened this issue Feb 14, 2019 · 0 comments

Comments

@av3
Copy link
Contributor

av3 commented Feb 14, 2019

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());
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant