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)
23
23
$ connectionHeaders = ('1.1 ' === $ this ->protocolVersion ) ? array ('Connection ' => 'close ' ) : array ();
24
24
$ authHeaders = $ this ->getAuthHeaders ();
25
25
26
- return array_merge (
26
+ $ defaults = array_merge (
27
27
array (
28
28
'Host ' => $ this ->getHost ().$ port ,
29
29
'User-Agent ' => 'React/alpha ' ,
30
30
),
31
31
$ connectionHeaders ,
32
- $ authHeaders ,
33
- $ headers
32
+ $ authHeaders
34
33
);
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 );
35
44
}
36
45
37
46
public function getScheme ()
Original file line number Diff line number Diff line change @@ -34,6 +34,23 @@ public function toStringReturnsHTTPRequestMessageWithProtocolVersion()
34
34
$ this ->assertSame ($ expected , $ requestData ->__toString ());
35
35
}
36
36
37
+ /** @test */
38
+ public function toStringReturnsHTTPRequestMessageWithHeadersInCustomCase ()
39
+ {
40
+ $ requestData = new RequestData ('GET ' , 'http://www.example.com ' , array (
41
+ 'user-agent ' => 'Hello ' ,
42
+ 'LAST ' => 'World '
43
+ ));
44
+
45
+ $ expected = "GET / HTTP/1.0 \r\n" .
46
+ "Host: www.example.com \r\n" .
47
+ "user-agent: Hello \r\n" .
48
+ "LAST: World \r\n" .
49
+ "\r\n" ;
50
+
51
+ $ this ->assertSame ($ expected , $ requestData ->__toString ());
52
+ }
53
+
37
54
/** @test */
38
55
public function toStringReturnsHTTPRequestMessageWithProtocolVersionThroughConstructor ()
39
56
{
You can’t perform that action at this time.
0 commit comments