File tree 3 files changed +60
-5
lines changed
lib/internal/Magento/Framework/HTTP
3 files changed +60
-5
lines changed Original file line number Diff line number Diff line change @@ -453,11 +453,8 @@ protected function parseHeaders($ch, $data)
453
453
}
454
454
455
455
if (strlen ($ name )) {
456
- if ("Set-Cookie " == $ name ) {
457
- if (!isset ($ this ->_responseHeaders [$ name ])) {
458
- $ this ->_responseHeaders [$ name ] = [];
459
- }
460
- $ this ->_responseHeaders [$ name ][] = $ value ;
456
+ if ('set-cookie ' === strtolower ($ name )) {
457
+ $ this ->_responseHeaders ['Set-Cookie ' ][] = $ value ;
461
458
} else {
462
459
$ this ->_responseHeaders [$ name ] = $ value ;
463
460
}
Original file line number Diff line number Diff line change @@ -26,4 +26,57 @@ public function testInvalidProtocol()
26
26
$ client = new Curl ();
27
27
$ client ->get ('telnet://127.0.0.1/test ' );
28
28
}
29
+
30
+ /**
31
+ * Check the HTTP client ability to parse headers case-insensitive.
32
+ */
33
+ public function testParseHeaders ()
34
+ {
35
+ // Prepare protected parseHeaders method
36
+ $ curl = new Curl ();
37
+ $ parseHeaders = new \ReflectionMethod (
38
+ $ curl ,
39
+ 'parseHeaders '
40
+ );
41
+ $ parseHeaders ->setAccessible (true );
42
+
43
+ // Parse headers
44
+ foreach ($ this ->headersDataProvider () as $ header ) {
45
+ $ parseHeaders ->invoke ($ curl , null , $ header );
46
+ }
47
+
48
+ // Validate headers
49
+ $ headers = $ curl ->getHeaders ();
50
+ $ this ->assertIsArray ($ headers );
51
+ $ this ->assertEquals ([
52
+ 'Content-Type ' => 'text/html; charset=utf-8 ' ,
53
+ 'Set-Cookie ' => [
54
+ 'Normal=OK ' ,
55
+ 'Uppercase=OK ' ,
56
+ 'Lowercase=OK ' ,
57
+ ]
58
+ ], $ headers );
59
+
60
+ // Validate status
61
+ $ status = $ curl ->getStatus ();
62
+ $ this ->assertIsInt ($ status );
63
+ $ this ->assertEquals (200 , $ status );
64
+
65
+ // Validate cookies
66
+ $ cookies = $ curl ->getCookies ();
67
+ $ this ->assertIsArray ($ cookies );
68
+ $ this ->assertEquals ([
69
+ 'Normal ' => 'OK ' ,
70
+ 'Uppercase ' => 'OK ' ,
71
+ 'Lowercase ' => 'OK ' ,
72
+ ], $ cookies );
73
+ }
74
+
75
+ /**
76
+ * @return array
77
+ */
78
+ public function headersDataProvider ()
79
+ {
80
+ return array_filter (explode (PHP_EOL , file_get_contents (__DIR__ . '/_files/curl_headers.txt ' )));
81
+ }
29
82
}
Original file line number Diff line number Diff line change
1
+ Status: 200 OK
2
+ Content-Type: text/html; charset=utf-8
3
+ Set-Cookie: Normal=OK
4
+ SET-COOKIE: Uppercase=OK
5
+ set-cookie: Lowercase=OK
You can’t perform that action at this time.
0 commit comments