Skip to content

Commit 89e384d

Browse files
author
Steve Miketa
committed
Add support for multiple continue headers
1 parent f2dae85 commit 89e384d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/VCR/Util/HttpUtil.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ public static function parseStatus($status)
6161
*/
6262
public static function parseResponse($response)
6363
{
64-
if (strpos($response, 'HTTP/1.1 100 Continue') === 0) {
65-
list($continueHeader, $rawHeader, $rawBody) = explode("\r\n\r\n", $response, 3);
66-
}
67-
else {
68-
list($rawHeader, $rawBody) = explode("\r\n\r\n", $response, 2);
69-
}
64+
$response = str_replace("HTTP/1.1 100 Continue\r\n\r\n", '', $response);
65+
66+
list($rawHeader, $rawBody) = explode("\r\n\r\n", $response, 2);
7067

7168
// Parse headers and status.
7269
$headers = self::parseRawHeader($rawHeader);

tests/VCR/Util/HttpUtilTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ public function testParseContinuePlusResponse()
5555
$this->assertEquals(null, $body);
5656
$this->assertEquals($expectedHeaders, $headers);
5757
}
58+
59+
public function testParseiMultipleContinuePlusResponse()
60+
{
61+
$raw = "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 100 Continue\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";
62+
list($status, $headers, $body) = HttpUtil::parseResponse($raw);
63+
64+
$expectedHeaders = array(
65+
'Content-Type: text/html',
66+
'Date: Fri, 19 Jun 2015 16:05:18 GMT',
67+
'Vary: Accept-Encoding',
68+
'Content-Length: 0'
69+
);
70+
71+
$this->assertEquals('HTTP/1.1 201 Created', $status);
72+
$this->assertEquals(null, $body);
73+
$this->assertEquals($expectedHeaders, $headers);
74+
}
75+
5876

5977
public function testParseContinuePlusResponseMultipleHeaders()
6078
{

0 commit comments

Comments
 (0)