From 1db90c402bded14b1ff5f269cde7275e9eb1e5d0 Mon Sep 17 00:00:00 2001 From: Jozef Rebjak Date: Mon, 26 Jun 2023 13:07:39 +0200 Subject: [PATCH 1/4] fix: skip http proxy added header --- system/HTTP/CURLRequest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 377f51e46006..616ef143fde8 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -387,6 +387,10 @@ public function send(string $method, string $url) $output = substr($output, strpos($output, $breakString) + 4); } + if (strpos($output, 'HTTP/1.1 200 Connection established') === 0) { + $output = substr($output, strpos($output, $breakString) + 4); + } + // If request and response have Digest if (isset($this->config['auth'][2]) && $this->config['auth'][2] === 'digest' && strpos($output, 'WWW-Authenticate: Digest') !== false) { $output = substr($output, strpos($output, $breakString) + 4); From 9a41f6b18c6e6e6ff8cdb34f4e82e11481d5ec9b Mon Sep 17 00:00:00 2001 From: Jozef Rebjak Date: Mon, 26 Jun 2023 13:52:36 +0200 Subject: [PATCH 2/4] test: add testSendProxied --- tests/system/HTTP/CURLRequestTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 92c43cc58461..41ebee307374 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -718,6 +718,18 @@ public function testSendContinued() $this->assertSame('Hi there', $response->getBody()); } + public function testSendProxied() + { + $request = $this->getRequest([ + 'base_uri' => 'http://www.foo.com/api/v1/', + 'delay' => 100, + ]); + + $request->setOutput("HTTP/1.1 200 Connection established:\x0d\x0a\x0d\x0aHi there"); + $response = $request->get('answer'); + $this->assertSame('Hi there', $response->getBody()); + } + /** * See: https://github.com/codeigniter4/CodeIgniter4/issues/3261 */ From 8d023d9255822e05c2b4622125518eec7348ce59 Mon Sep 17 00:00:00 2001 From: Jozef Rebjak Date: Mon, 26 Jun 2023 13:55:32 +0200 Subject: [PATCH 3/4] fix: testSendProxied typo --- tests/system/HTTP/CURLRequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 41ebee307374..d1ae4ea5db06 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -725,7 +725,7 @@ public function testSendProxied() 'delay' => 100, ]); - $request->setOutput("HTTP/1.1 200 Connection established:\x0d\x0a\x0d\x0aHi there"); + $request->setOutput("HTTP/1.1 200 Connection established\x0d\x0a\x0d\x0aHi there"); $response = $request->get('answer'); $this->assertSame('Hi there', $response->getBody()); } From a20365b9c9877a4f6cc050403889439a69099371 Mon Sep 17 00:00:00 2001 From: Jozef Rebjak Date: Mon, 26 Jun 2023 14:02:04 +0200 Subject: [PATCH 4/4] test: improve testSendProxied --- tests/system/HTTP/CURLRequestTest.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index d1ae4ea5db06..d90b8847cbb6 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -718,18 +718,6 @@ public function testSendContinued() $this->assertSame('Hi there', $response->getBody()); } - public function testSendProxied() - { - $request = $this->getRequest([ - 'base_uri' => 'http://www.foo.com/api/v1/', - 'delay' => 100, - ]); - - $request->setOutput("HTTP/1.1 200 Connection established\x0d\x0a\x0d\x0aHi there"); - $response = $request->get('answer'); - $this->assertSame('Hi there', $response->getBody()); - } - /** * See: https://github.com/codeigniter4/CodeIgniter4/issues/3261 */ @@ -777,6 +765,21 @@ public function testSendContinuedWithManyHeaders() $this->assertSame(200, $response->getStatusCode()); } + public function testSendProxied() + { + $request = $this->getRequest([ + 'base_uri' => 'http://www.foo.com/api/v1/', + 'delay' => 100, + ]); + + $output = "HTTP/1.1 200 Connection established +Proxy-Agent: Fortinet-Proxy/1.0\x0d\x0a\x0d\x0aHTTP/1.1 200 OK\x0d\x0a\x0d\x0aHi there"; + $request->setOutput($output); + + $response = $request->get('answer'); + $this->assertSame('Hi there', $response->getBody()); + } + /** * See: https://github.com/codeigniter4/CodeIgniter4/issues/7394 */