From 2de7be1686e29574e5afd07779de250b1ca459a5 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Sat, 27 Jan 2024 13:41:00 +0800 Subject: [PATCH 1/4] fix: fix the repeat status code 100 problem. --- system/HTTP/CURLRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 500b425d2dc5..dfc9ba97f7b2 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -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); } From 917607cd47457718c668bf31437fae6e670c6d29 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Sun, 28 Jan 2024 17:55:08 +0800 Subject: [PATCH 2/4] test: add the test case for multiple HTTP100. --- tests/system/HTTP/CURLRequestTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 4893266e5009..46da73fe736c 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -1109,4 +1109,24 @@ public function testUserAgentOption(): void $this->assertArrayHasKey(CURLOPT_USERAGENT, $options); $this->assertSame($agent, $options[CURLOPT_USERAGENT]); } + + public function testMultipleHTTP100(): void + { + $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 + Connection: close'; + + $this->request->setOutput($output); + + $response = $this->request->request('get', 'http://example.com'); + + $this->assertSame(200, $response->getStatusCode()); + } } From 0c166d2887b897bc5d768fcd5ad1a7ced49c9028 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Tue, 13 Feb 2024 16:41:23 +0800 Subject: [PATCH 3/4] test: fix the testcase to follow the http response spec. --- tests/system/HTTP/CURLRequestTest.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 46da73fe736c..66ad0d7cc6df 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -1110,23 +1110,29 @@ public function testUserAgentOption(): void $this->assertSame($agent, $options[CURLOPT_USERAGENT]); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/8347 + */ public function testMultipleHTTP100(): void { - $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 - Connection: close'; + $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()); } } From 39e2283717e26964a404fdffc8f217350f3d24da Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 14 Feb 2024 11:09:01 +0900 Subject: [PATCH 4/4] fix: HTTP method name should be uppercase --- 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 66ad0d7cc6df..3115f86aedbb 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -1129,7 +1129,7 @@ public function testMultipleHTTP100(): void $this->request->setOutput($output); - $response = $this->request->request('get', 'http://example.com'); + $response = $this->request->request('GET', 'http://example.com'); $this->assertSame($jsonBody, $response->getBody());