Skip to content

Commit bc0517f

Browse files
authored
Merge pull request #8466 from ping-yee/240127_curlrequest
fix: [CURLRequest] Multiple HTTP 100 return by API.
2 parents 667b324 + 39e2283 commit bc0517f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

system/HTTP/CURLRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public function send(string $method, string $url)
389389
// Set the string we want to break our response from
390390
$breakString = "\r\n\r\n";
391391

392-
if (strpos($output, 'HTTP/1.1 100 Continue') === 0) {
392+
while (strpos($output, 'HTTP/1.1 100 Continue') === 0) {
393393
$output = substr($output, strpos($output, $breakString) + 4);
394394
}
395395

tests/system/HTTP/CURLRequestTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,4 +1109,30 @@ public function testUserAgentOption(): void
11091109
$this->assertArrayHasKey(CURLOPT_USERAGENT, $options);
11101110
$this->assertSame($agent, $options[CURLOPT_USERAGENT]);
11111111
}
1112+
1113+
/**
1114+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8347
1115+
*/
1116+
public function testMultipleHTTP100(): void
1117+
{
1118+
$jsonBody = '{"name":"John Doe","age":30}';
1119+
1120+
$output = "HTTP/1.1 100 Continue
1121+
Mark bundle as not supporting multiuse
1122+
HTTP/1.1 100 Continue
1123+
Mark bundle as not supporting multiuse
1124+
HTTP/1.1 200 OK
1125+
Server: Werkzeug/2.2.2 Python/3.7.17
1126+
Date: Sun, 28 Jan 2024 06:05:36 GMT
1127+
Content-Type: application/json
1128+
Content-Length: 33\r\n\r\n" . $jsonBody;
1129+
1130+
$this->request->setOutput($output);
1131+
1132+
$response = $this->request->request('GET', 'http://example.com');
1133+
1134+
$this->assertSame($jsonBody, $response->getBody());
1135+
1136+
$this->assertSame(200, $response->getStatusCode());
1137+
}
11121138
}

0 commit comments

Comments
 (0)