Skip to content

Commit efefd88

Browse files
committed
Fix response parsing when 100 Continue response contains optional headers
1 parent b2435aa commit efefd88

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Curl.class.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ private function parseResponse($response)
284284
$response_headers = '';
285285
if (!(strpos($response, "\r\n\r\n") === false)) {
286286
list($response_header, $response) = explode("\r\n\r\n", $response, 2);
287-
if ($response_header === 'HTTP/1.1 100 Continue') {
287+
$response_headers = array($response_header);
288+
if (!(strpos($response_header, "\r\n") === false)) {
289+
$response_headers = explode("\r\n", $response_header);
290+
}
291+
if (in_array('HTTP/1.1 100 Continue', $response_headers)) {
288292
list($response_header, $response) = explode("\r\n\r\n", $response, 2);
289293
}
290294
$response_headers = $this->parseResponseHeaders($response_header);

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,39 @@ public function testPostRequestMethod() {
8585
)) === 'POST');
8686
}
8787

88+
public function testPostContinueResponse() {
89+
// 100 Continue responses may contain additional optional headers per
90+
// RFC 2616, Section 10.1:
91+
// This class of status code indicates a provisional response,
92+
// consisting only of the Status-Line and optional headers, and is
93+
// terminated by an empty line.
94+
$response =
95+
'HTTP/1.1 100 Continue' . "\r\n" .
96+
'Date: Fri, 01 Jan 1990 00:00:00 GMT' . "\r\n" .
97+
'Server: PHP-Curl-Class' . "\r\n" .
98+
"\r\n" .
99+
'HTTP/1.1 200 OK' . "\r\n" .
100+
'Date: Fri, 01 Jan 1990 00:00:00 GMT' . "\r\n" .
101+
'Cache-Control: private' . "\r\n" .
102+
'Vary: Accept-Encoding' . "\r\n" .
103+
'Content-Length: 2' . "\r\n" .
104+
'Content-Type: text/plain;charset=UTF-8' . "\r\n" .
105+
'Server: PHP-Curl-Class' . "\r\n" .
106+
'Connection: keep-alive' . "\r\n" .
107+
"\r\n" .
108+
'OK';
109+
110+
$reflector = new ReflectionClass('Curl');
111+
$reflection_method = $reflector->getMethod('parseResponse');
112+
$reflection_method->setAccessible(true);
113+
114+
$curl = new Curl();
115+
list($response_headers, $response) = $reflection_method->invoke($curl, $response);
116+
117+
$this->assertEquals($response_headers['Status-Line'], 'HTTP/1.1 200 OK');
118+
$this->assertEquals($response, 'OK');
119+
}
120+
88121
public function testPostData() {
89122
$test = new Test();
90123
$this->assertTrue($test->server('post', 'POST', array(

0 commit comments

Comments
 (0)