Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/VCR/Util/CurlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CurlHelper
\CURLINFO_CONTENT_LENGTH_DOWNLOAD => 'download_content_length',
\CURLINFO_CONTENT_LENGTH_UPLOAD => 'upload_content_length',
\CURLINFO_CONTENT_TYPE => 'content_type',
\CURLINFO_APPCONNECT_TIME => 'appconect_time'
];

/**
Expand Down Expand Up @@ -107,6 +108,7 @@ public static function getCurlOptionFromResponse(Response $response, int $option
$info = mb_strlen(HttpUtil::formatAsStatusWithHeadersString($response), 'ISO-8859-1');
break;
case \CURLPROXY_HTTPS:
case \CURLINFO_APPCONNECT_TIME:
$info = '';
break;
default:
Expand Down
15 changes: 13 additions & 2 deletions src/VCR/Util/HttpUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,20 @@ public static function parseStatus(string $status): array
*/
public static function parseResponse(string $response): array
{
$response = str_replace("HTTP/1.1 100 Continue\r\n\r\n", '', $response);
$parts = explode("\r\n\r\n", $response);

[$rawHeader, $rawBody] = explode("\r\n\r\n", $response, 2);
$headerIndex = 0;
foreach ($parts as $index => $part) {
if (str_starts_with($part, 'HTTP/')) {
$headerIndex = $index;
} else {
break;
}
}

$rawHeader = $parts[$headerIndex];
$bodyParts = \array_slice($parts, $headerIndex + 1);
$rawBody = implode('\r\n\r\n', $bodyParts);

// Parse headers and status.
$headers = self::parseRawHeader($rawHeader);
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Util/HttpUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ public function testParseContinuePlusResponseMultipleHeaders(): void
$this->assertEquals($expectedHeaders, $headers);
}

public function testParseMultipleResponseCodes(): void
{
$raw = "HTTP/1.1 200 OK\r\n\r\nHTTP/1.1 200 OK\r\n\r\nHTTP/1.1 201 Created\r\nContent-Type: text/html\r\nDate: Fri, 19 Jun 2015 16:05:18 GMT\r\nVary: Accept-Encoding\r\nContent-Length: 0\r\n\r\n";
[$status, $headers, $body] = HttpUtil::parseResponse($raw);

$expectedHeaders = [
'Content-Type: text/html',
'Date: Fri, 19 Jun 2015 16:05:18 GMT',
'Vary: Accept-Encoding',
'Content-Length: 0',
];

$this->assertEquals('HTTP/1.1 201 Created', $status);
$this->assertEquals('', $body);
$this->assertEquals($expectedHeaders, $headers);
}

public function testParseHeadersBasic(): void
{
$inputArray = [
Expand Down