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 @@ -106,6 +106,23 @@ public function toStringReturnsHTTPRequestMessageWithHeaders()
106106 $ this ->assertSame ($ expected , $ requestData ->__toString ());
107107 }
108108
109+ /** @test */
110+ public function toStringReturnsHTTPRequestMessageWithHeadersInCustomCase ()
111+ {
112+ $ requestData = new RequestData ('GET ' , 'http://www.example.com ' , array (
113+ 'user-agent ' => 'Hello ' ,
114+ 'LAST ' => 'World '
115+ ));
116+
117+ $ expected = "GET / HTTP/1.0 \r\n" .
118+ "Host: www.example.com \r\n" .
119+ "user-agent: Hello \r\n" .
120+ "LAST: World \r\n" .
121+ "\r\n" ;
122+
123+ $ this ->assertSame ($ expected , $ requestData ->__toString ());
124+ }
125+
109126 /** @test */
110127 public function toStringReturnsHTTPRequestMessageWithProtocolVersionThroughConstructor ()
111128 {
You can’t perform that action at this time.
0 commit comments