From 63df99d6a1e6ddb65d097811b15bba8f65a53f2a Mon Sep 17 00:00:00 2001 From: Alexander Zinovev Date: Tue, 15 Oct 2019 12:14:10 +0200 Subject: [PATCH] CURL Transport: Add processing of multiple HTTP headers in response. --- src/Klarna/Rest/Transport/CURLConnector.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Klarna/Rest/Transport/CURLConnector.php b/src/Klarna/Rest/Transport/CURLConnector.php index fc7596c..439a9b7 100644 --- a/src/Klarna/Rest/Transport/CURLConnector.php +++ b/src/Klarna/Rest/Transport/CURLConnector.php @@ -234,11 +234,12 @@ protected function request($method, $url, array $headers = [], $data = null) } } - $rawContent = curl_exec($ch); + $response = curl_exec($ch); $errno = curl_errno($ch); $error = curl_error($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close($ch); @@ -247,10 +248,11 @@ protected function request($method, $url, array $headers = [], $data = null) throw new \RuntimeException($error, $errno); } - list($rawHeaders, $content) = preg_split("/(\r?\n){2}/", $rawContent, 2); + $rawHeaders = substr($response, 0, $header_size); + $body = substr($response, $header_size); $headers = self::parseHeaders($rawHeaders); - return new ApiResponse($http_code, $content, $headers); + return new ApiResponse($http_code, $body, $headers); } /** @@ -284,8 +286,12 @@ protected static function parseHeaders($rawHeaders) { $headers = []; foreach (explode("\r\n", $rawHeaders) as $i => $line) { - if ($i == 0) { - // The first line contains the HTTP response information + if (strlen($line) == 0) { + continue; + } + + if (strpos($line, 'HTTP/') !== false) { + // The line contains the HTTP response information $headers['Http'] = $line; continue; }