diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 8a9598b92e8e..3ee990a145ef 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -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 diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 217ecc198e94..17365350eb0a 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -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