Skip to content

Commit

Permalink
Merge pull request #8466 from ping-yee/240127_curlrequest
Browse files Browse the repository at this point in the history
fix: [CURLRequest] Multiple HTTP 100 return by API.
  • Loading branch information
kenjis authored Feb 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 667b324 + 39e2283 commit bc0517f
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
@@ -389,7 +389,7 @@ public function send(string $method, string $url)
// Set the string we want to break our response from
$breakString = "\r\n\r\n";

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

26 changes: 26 additions & 0 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
@@ -1109,4 +1109,30 @@ public function testUserAgentOption(): void
$this->assertArrayHasKey(CURLOPT_USERAGENT, $options);
$this->assertSame($agent, $options[CURLOPT_USERAGENT]);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/8347
*/
public function testMultipleHTTP100(): void
{
$jsonBody = '{"name":"John Doe","age":30}';

$output = "HTTP/1.1 100 Continue
Mark bundle as not supporting multiuse
HTTP/1.1 100 Continue
Mark bundle as not supporting multiuse
HTTP/1.1 200 OK
Server: Werkzeug/2.2.2 Python/3.7.17
Date: Sun, 28 Jan 2024 06:05:36 GMT
Content-Type: application/json
Content-Length: 33\r\n\r\n" . $jsonBody;

$this->request->setOutput($output);

$response = $this->request->request('GET', 'http://example.com');

$this->assertSame($jsonBody, $response->getBody());

$this->assertSame(200, $response->getStatusCode());
}
}

0 comments on commit bc0517f

Please sign in to comment.