Skip to content

Commit

Permalink
Merge pull request #3274 from michalsn/fix/continue
Browse files Browse the repository at this point in the history
Fix "100 Continue" header handling in CURLRequest class
  • Loading branch information
michalsn authored Jul 12, 2020
2 parents 6cf6c8b + ea0bc83 commit fdda2e7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
5 changes: 2 additions & 3 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,9 @@ public function send(string $method, string $url)

$output = $this->sendRequest($curl_options);

$continueStr = "HTTP/1.1 100 Continue\x0d\x0a\x0d\x0a";
if (strpos($output, $continueStr) === 0)
if (strpos($output, 'HTTP/1.1 100 Continue') === 0)
{
$output = substr($output, strlen($continueStr));
$output = substr($output, strpos($output, "\r\n\r\n") + 4);
}

// Split out our headers and body
Expand Down
47 changes: 47 additions & 0 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,53 @@ public function testSendContinued()
$this->assertEquals('Hi there', $response->getBody());
}

/**
* See: https://github.com/codeigniter4/CodeIgniter4/issues/3261
*/
public function testSendContinuedWithManyHeaders()
{
$request = $this->getRequest([
'base_uri' => 'http://www.foo.com/api/v1/',
'delay' => 1000,
]);

$output = "HTTP/1.1 100 Continue
Server: ddos-guard
Set-Cookie: __ddg1=z177j4mLtqzC07v0zviU; Domain=.site.ru; HttpOnly; Path=/; Expires=Wed, 07-Jul-2021 15:13:14 GMT\x0d\x0a\x0d\x0aHTTP/1.1 200 OK
Server: ddos-guard
Connection: keep-alive
Keep-Alive: timeout=60
Set-Cookie: __ddg1=z177j4mLtqzC07v0zviU; Domain=.site.ru; HttpOnly; Path=/; Expires=Wed, 07-Jul-2021 15:13:14 GMT
Date: Tue, 07 Jul 2020 15:13:14 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: PHPSESSID=80pd3hlg38mvjnelpvokp9lad0; path=/
Content-Type: application/xml; charset=utf-8
Transfer-Encoding: chunked\x0d\x0a\x0d\x0a<title>Update success! config</title>";

$request->setOutput($output);
$response = $request->get('answer');

$this->assertEquals('<title>Update success! config</title>', $response->getBody());

$responseHeaderKeys = [
'Cache-control',
'Content-Type',
'Server',
'Connection',
'Keep-Alive',
'Set-Cookie',
'Date',
'Expires',
'Pragma',
'Transfer-Encoding',
];
$this->assertEquals($responseHeaderKeys, array_keys($response->getHeaders()));

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

//--------------------------------------------------------------------
public function testSplitResponse()
{
Expand Down

0 comments on commit fdda2e7

Please sign in to comment.