File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments