You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,8 @@ multiple concurrent HTTP requests without blocking.
69
69
* [withBase()](#withbase)
70
70
* [withProtocolVersion()](#withprotocolversion)
71
71
* [withResponseBuffer()](#withresponsebuffer)
72
+
* [withHeader()](#withheader)
73
+
* [withoutHeader()](#withoutheader)
72
74
*[React\Http\Message](#reacthttpmessage)
73
75
*[Response](#response)
74
76
* [html()](#html)
@@ -2381,6 +2383,20 @@ Notice that the [`Browser`](#browser) is an immutable object, i.e. this
2381
2383
method actually returns a *new*[`Browser`](#browser) instance with the
2382
2384
given setting applied.
2383
2385
2386
+
#### withHeader()
2387
+
2388
+
The `withHeader(string $header, string $value): Browser` method can be used to
2389
+
add a request header for all following requests.
2390
+
2391
+
Note that the new header will overwrite any headers previously set with the same name (case-insensitive). Following requests will use these headers by default unless they are explicitly set for any requests.
2392
+
2393
+
#### withoutHeader()
2394
+
2395
+
The `withoutHeader(string $header): Browser` method can be used to
2396
+
remove any default request headers previously set via the [`withHeader()` method](#withheader).
2397
+
2398
+
Note that this method only affects the headers which were set with the method `withHeader(string $header, string $value): Browser`
Copy file name to clipboardExpand all lines: src/Browser.php
+58Lines changed: 58 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,9 @@ class Browser
23
23
private$transaction;
24
24
private$baseUrl;
25
25
private$protocolVersion = '1.1';
26
+
private$defaultHeaders = array(
27
+
'User-Agent' => 'ReactPHP/1',
28
+
);
26
29
27
30
/**
28
31
* The `Browser` is responsible for sending HTTP requests to your HTTP server
@@ -725,6 +728,49 @@ public function withResponseBuffer($maximumSize)
725
728
));
726
729
}
727
730
731
+
/**
732
+
* The `withHeader(string $header, string $value): Browser` method can be used to
733
+
* add a request header for all following requests.
734
+
*
735
+
* Note that the new header will overwrite any headers previously set with the same name (case-insensitive). Following requests will use these headers by default unless they are explicitly set for any requests.
736
+
*
737
+
* @param string $header
738
+
* @param string $value
739
+
* @return Browser
740
+
*/
741
+
publicfunctionwithHeader($header, $value)
742
+
{
743
+
$browser = $this->withoutHeader($header);
744
+
$browser->defaultHeaders[$header] = $value;
745
+
746
+
return$browser;
747
+
}
748
+
749
+
/**
750
+
*
751
+
* The `withoutHeader(string $header): Browser` method can be used to
752
+
* remove any default request headers previously set via the [`withHeader()` method](#withheader).
753
+
*
754
+
* Note that this method only affects the headers which were set with the method `withHeader(string $header, string $value): Browser`
0 commit comments