Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
Merge 63df99d into c09aa01
Browse files Browse the repository at this point in the history
  • Loading branch information
alexions committed Oct 15, 2019
2 parents c09aa01 + 63df99d commit 294366f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Klarna/Rest/Transport/CURLConnector.php
Expand Up @@ -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);

Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 294366f

Please sign in to comment.