File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -23,15 +23,24 @@ private function mergeDefaultheaders(array $headers)
2323 $ connectionHeaders = ('1.1 ' === $ this ->protocolVersion ) ? array ('Connection ' => 'close ' ) : array ();
2424 $ authHeaders = $ this ->getAuthHeaders ();
2525
26- return array_merge (
26+ $ defaults = array_merge (
2727 array (
2828 'Host ' => $ this ->getHost ().$ port ,
2929 'User-Agent ' => 'React/alpha ' ,
3030 ),
3131 $ connectionHeaders ,
32- $ authHeaders ,
33- $ headers
32+ $ authHeaders
3433 );
34+
35+ // remove all defaults that already exist in $headers
36+ $ lower = array_change_key_case ($ headers , CASE_LOWER );
37+ foreach ($ defaults as $ key => $ _ ) {
38+ if (isset ($ lower [strtolower ($ key )])) {
39+ unset($ defaults [$ key ]);
40+ }
41+ }
42+
43+ return array_merge ($ defaults , $ headers );
3544 }
3645
3746 public function getScheme ()
Original file line number Diff line number Diff line change @@ -54,6 +54,23 @@ public function toStringReturnsHTTPRequestMessageWithHeaders()
5454 $ this ->assertSame ($ expected , $ requestData ->__toString ());
5555 }
5656
57+ /** @test */
58+ public function toStringReturnsHTTPRequestMessageWithHeadersInCustomCase ()
59+ {
60+ $ requestData = new RequestData ('GET ' , 'http://www.example.com ' , array (
61+ 'user-agent ' => 'Hello ' ,
62+ 'LAST ' => 'World '
63+ ));
64+
65+ $ expected = "GET / HTTP/1.0 \r\n" .
66+ "Host: www.example.com \r\n" .
67+ "user-agent: Hello \r\n" .
68+ "LAST: World \r\n" .
69+ "\r\n" ;
70+
71+ $ this ->assertSame ($ expected , $ requestData ->__toString ());
72+ }
73+
5774 /** @test */
5875 public function toStringReturnsHTTPRequestMessageWithProtocolVersionThroughConstructor ()
5976 {
You can’t perform that action at this time.
0 commit comments