The library provides several middleware classes for the guzzle http client.
- PHP 7.1+
$ composer require tommyseus/guzzlehttp-middleware
The encoding middleware converts the response to the expected encoding. It will modify the body and the content-type header of the response. It's possible to to add the encoding middleware to the handler stack or add it to the promise-then method.
$stack = \GuzzleHttp\HandlerStack::create();
$stack->push(\GuzzleHttp\Middleware::mapResponse(new \Seus\GuzzleHttp\Middleware\Encoding('UTF-8')));
return new \GuzzleHttp\Client([
'handler' => $stack,
]);
/* @var $client \GuzzleHttp\Client */
$promise = $client->requestAsync('GET', '......');
$promise->then(new \Seus\GuzzleHttp\Middleware\Encoding('UTF-8'));
$promise->then(
function (\Psr\Http\Message\ResponseInterface $res) {
echo $res->getStatusCode();
}
);
$promise->wait();
$ docker-compose run guzzlehttp-middleware-php72 composer check
$ docker-compose run guzzlehttp-middleware-php71 composer check