Skip to content

Commit 3bc4865

Browse files
committed
Header plugin
1 parent 1989a3d commit 3bc4865

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

plugins/header.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Header Plugin
2+
=============
3+
4+
The header plugin allows to set or remove headers from the request::
5+
6+
use Http\Discovery\HttpClientDiscovery;
7+
use Http\Plugins\PluginClient;
8+
use Http\Plugins\HeaderPlugin;
9+
10+
$headerPlugin = new HeaderPlugin($authentication);
11+
12+
// Set the header 'Content-Type' to the value 'application/json'
13+
// Only if the request does not already defines a 'Content-Type' header
14+
$headerPlugin->withHeader('Content-Type', 'application/json');
15+
16+
// Note the third param to true:
17+
// We want every request to have the following 'User-Agent' header
18+
// If the request already defines a 'User-Agent' header it will be replaced with this one
19+
$headerPlugin->withHeader('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:12.0)', true);
20+
21+
22+
// We dont want the request to have 'Cookie' header
23+
$headerPlugin->withoutHeader('Cookie');
24+
25+
26+
$pluginClient = new PluginClient(
27+
HttpClientDiscovery::find(),
28+
[$headerPlugin]
29+
);
30+

0 commit comments

Comments
 (0)