Closed
Description
Preconditions (*)
Magento v2.3.3
Steps to reproduce (*)
- Make a call with the
GraphQlAbstract::graphQlQueryWithResponseHeaders
- Have a header in the response like:
Access-Control-Allow-Origin: https://www.example.com
- See that the header does NOT show up in the headers array
Expected result (*)
- Have a header in the headers array like:
['Access-Control-Allow-Origin'] => 'https://www.example.com'
Actual result (*)
See above.
This is due to a failed preg_split
logic in:
/**
* Parse response headers into associative array
*
* @param string $headers
* @return array
*/
private function processResponseHeaders(string $headers): array
{
$headersArray = [];
$headerLines = preg_split('/((\r?\n)|(\r\n?))/', $headers);
foreach ($headerLines as $headerLine) {
$headerParts = preg_split('/: /', $headerLine);
if (count($headerParts) == 2) {
$headersArray[trim($headerParts[0])] = trim($headerParts[1]);
} elseif (preg_match('/HTTP\/[\.0-9]+/', $headerLine)) {
$headersArray[trim('Status-Line')] = trim($headerLine);
}
}
return $headersArray;
}
It should preg_split
with a limit of 2
:
$headerParts = preg_split('/: /', $headerLine, 2);