tommyseus/guzzlehttp-middleware

The library provides several middleware classes for the guzzle http client.

0.1.0 2018-11-12 19:47 UTC

This package is auto-updated.

Last update: 2024-11-13 11:27:53 UTC


README

Latest Stable Version License Build Status Coverage Status

The library provides several middleware classes for the guzzle http client.

Installation

Requirements

  • PHP 7.1+

Composer installation

$ composer require tommyseus/guzzlehttp-middleware

Encoding 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();

Run tests

$ docker-compose run guzzlehttp-middleware-php72 composer check

$ docker-compose run guzzlehttp-middleware-php71 composer check