amphp / http-client-psr7

PSR-7 adapter for amphp/http-client.
MIT License
10 stars 3 forks source link

PSR7Adapter fails with protocol version 2.0 #15

Closed bwoebi closed 1 week ago

bwoebi commented 2 weeks ago

amphp/http-client expects 2, but PSRAdapter accepts a 2.0 too.

Invalid HTTP protocol version: 2.0 at vendor/amphp/http-client/src/Request.php:126
#0 vendor/amphp/http-client-psr7/src/PsrAdapter.php(31): Amp\\Http\\Client\\Request->setProtocolVersions()
#1 vendor/amphp/http-client-guzzle-adapter/src/GuzzleHandlerAdapter.php(85): Amp\\Http\\Client\\Psr7\\PsrAdapter->fromPsrRequest()

A trivial workaround would be

        $protocolVersion = $source->getProtocolVersion();
        $target->setProtocolVersions([$protocolVersion == "2.0" ? "2" : $protocolVersion]);

in https://github.com/amphp/http-client-psr7/blob/6c7589a22f06772794ad38114c980bce8d85b14e/src/PsrAdapter.php#L31

I think this is the right place to change it and not make amphp/http-client support it though.

bwoebi commented 1 week ago

@trowski The 394f2c59e31eaf16f9e64b1317324e26b7f8e4e4 commit looks good to me - can we merge it?