Skip to content

Commit 399f077

Browse files
ENGCOM-8107: Update Curl to respect case-insensitive headers #29274
- Merge Pull Request #29274 from pmzandbergen/magento2:patch-1 - Merged commits: 1. 44d88e6 2. ba6513f 3. 730c495 4. 552e0c1 5. b5463b8 6. e43e45f 7. e1d21cd 8. 9570f8f 9. 9db1f83 10. d61e030 11. e912bdf 12. d5c674d
2 parents b9c13fd + d5c674d commit 399f077

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

lib/internal/Magento/Framework/HTTP/Client/Curl.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,8 @@ protected function parseHeaders($ch, $data)
453453
}
454454

455455
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;
461458
} else {
462459
$this->_responseHeaders[$name] = $value;
463460
}

lib/internal/Magento/Framework/HTTP/Test/Unit/Client/CurlTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,57 @@ public function testInvalidProtocol()
2626
$client = new Curl();
2727
$client->get('telnet://127.0.0.1/test');
2828
}
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+
}
2982
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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

0 commit comments

Comments
 (0)