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 @@ -54,6 +54,23 @@ public function toStringReturnsHTTPRequestMessageWithHeaders()
54
54
$ this ->assertSame ($ expected , $ requestData ->__toString ());
55
55
}
56
56
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
+
57
74
/** @test */
58
75
public function toStringReturnsHTTPRequestMessageWithProtocolVersionThroughConstructor ()
59
76
{
You can’t perform that action at this time.
0 commit comments