Middleware for setting headers on all requests sent by a Guzzle 6 client

0.2 2019-03-25 12:56 UTC

This package is auto-updated.

Last update: 2023-05-25 22:03:53 UTC



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