webignition/guzzle-request-headers-middleware

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: 2021-12-25 19:03:48 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);