tommyseus / guzzlehttp-middleware
The library provides several middleware classes for the guzzle http client.
0.1.0
2018-11-12 19:47 UTC
Requires
- php: ^7.1
- guzzlehttp/guzzle: ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.13.1
- jangregor/phpstan-prophecy: ^0.2.0
- michaelmoussa/php-coverage-checker: ^1.1.0
- phpstan/phpstan: ^0.10.5
- phpstan/phpstan-phpunit: ^0.10.0
- phpunit/phpunit: ^7.4.3
This package is auto-updated.
Last update: 2024-11-13 11:27:53 UTC
README
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