webignition / guzzle-request-headers-middleware
Middleware for setting headers on all requests sent by a Guzzle 6 client
Installs: 29 837
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.0
- psr/http-message: ~1.0
Requires (Dev)
- mockery/mockery: ~1
- phpstan/phpstan: ^0.11.4
- phpstan/phpstan-mockery: ^0.11.0
- phpunit/phpunit: ^5
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-10-26 01:12:46 UTC
README
Overview
Middleware for Guzzle 6 for setting headers on all requests sent by a client.
Add any number of headers to every request sent by a client. That's it. Easy.
Usage example
use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use webignition\Guzzle\Middleware\RequestHeaders\RequestHeadersMiddleware; // Creating a client that uses the middleware $requestHeadersMiddleware = new RequestHeadersMiddleware(); $handlerStack = HandlerStack::create(); $handlerStack->push($requestHeadersMiddleware, 'request-headers'); $client = new Client([ 'handler' => $handlerStack, ]); // Setting request headers $requestHeadersMiddleware->setHeader('User-Agent', 'Super Foo!'); // All requests to example.com (or *.example.com) will now have // a header of 'User-Agent: Super Foo!' // Clearing request headers by explicitly setting a previously-set value to null $requestHeadersMiddleware->setHeader('User-Agent', null);