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
+41-15Lines changed: 41 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,9 @@ class Browser
23
23
private$transaction;
24
24
private$baseUrl;
25
25
private$protocolVersion = '1.1';
26
-
private$headers = array();
26
+
private$defaultHeaders = array(
27
+
'User-Agent' => 'ReactPHP/1',
28
+
);
27
29
28
30
/**
29
31
* The `Browser` is responsible for sending HTTP requests to your HTTP server
@@ -727,26 +729,43 @@ public function withResponseBuffer($maximumSize)
727
729
}
728
730
729
731
/**
730
-
* @param $header
731
-
* @param $value
732
-
* @return Browser
733
-
*@todo documentation
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.
734
736
*
737
+
* @param string $header
738
+
* @param string $value
739
+
* @return Browser
735
740
*/
736
741
publicfunctionwithHeader($header, $value)
737
742
{
738
-
$browser = clone$this;
739
-
$browser->headers[$header] = $value;
743
+
$browser = $this->withoutHeader($header);
744
+
$browser->defaultHeaders[$header] = $value;
740
745
741
746
return$browser;
742
747
}
743
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`
755
+
*
756
+
* @param string $header
757
+
* @return Browser
758
+
*/
744
759
publicfunctionwithoutHeader($header)
745
760
{
746
761
$browser = clone$this;
747
762
748
-
if (array_key_exists($header, $browser->headers)) {
0 commit comments