Auto change protocol version extension for PSR-18 HTTP client.
Install this package and your favorite psr-18 implementation.
composer require webclient/ext-protocol-version:^2.0
<?php
use Webclient\Extension\ProtocolVersion\ProtocolClientDecorator;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
/**
* @var ClientInterface $client Your PSR-18 HTTP Client
*/
$http = new ProtocolClientDecorator($client);
/** @var RequestInterface $request */
$response = $http->sendRequest($request);
If server returns a 505 error, this client will repeat the request with the protocol version specified in the server response.