Skip to content

Commit f2dae85

Browse files
stevemiketaSteve Miketa
authored andcommitted
Add support for HTTP Continue headers
Continue response headers now don't break response parsing
1 parent dfb1869 commit f2dae85

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/VCR/Util/HttpUtil.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ public static function parseStatus($status)
6161
*/
6262
public static function parseResponse($response)
6363
{
64-
list($rawHeader, $rawBody) = explode("\r\n\r\n", $response, 2);
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+
}
6570

6671
// Parse headers and status.
6772
$headers = self::parseRawHeader($rawHeader);

tests/VCR/Util/HttpUtilTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,41 @@ public function testParseResponseMultipleHeaders()
3939
$this->assertEquals($expectedHeaders, $headers);
4040
}
4141

42+
public function testParseContinuePlusResponse()
43+
{
44+
$raw = "HTTP/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";
45+
list($status, $headers, $body) = HttpUtil::parseResponse($raw);
46+
47+
$expectedHeaders = array(
48+
'Content-Type: text/html',
49+
'Date: Fri, 19 Jun 2015 16:05:18 GMT',
50+
'Vary: Accept-Encoding',
51+
'Content-Length: 0'
52+
);
53+
54+
$this->assertEquals('HTTP/1.1 201 Created', $status);
55+
$this->assertEquals(null, $body);
56+
$this->assertEquals($expectedHeaders, $headers);
57+
}
58+
59+
public function testParseContinuePlusResponseMultipleHeaders()
60+
{
61+
$raw = "HTTP/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, Accept-Language, Expect\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, Accept-Language, Expect',
68+
'Vary: Accept-Encoding',
69+
'Content-Length: 0'
70+
);
71+
72+
$this->assertEquals('HTTP/1.1 201 Created', $status);
73+
$this->assertEquals(null, $body);
74+
$this->assertEquals($expectedHeaders, $headers);
75+
}
76+
4277
public function testParseHeadersBasic()
4378
{
4479
$inputArray = array(

0 commit comments

Comments
 (0)