Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: [CURLRequest] Multiple HTTP 100 return by API #8347

Closed
PhpEssential opened this issue Dec 19, 2023 · 6 comments · Fixed by #8466
Closed

Bug: [CURLRequest] Multiple HTTP 100 return by API #8347

PhpEssential opened this issue Dec 19, 2023 · 6 comments · Fixed by #8466
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@PhpEssential
Copy link

PhpEssential commented Dec 19, 2023

PHP Version

8.1

CodeIgniter4 Version

4.4.2

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows, Linux

Which server did you use?

apache

Database

No response

What happened?

When I call API built with a Flask server, this one return these headers:

HTTP/1.1 100 Continue

HTTP/1.1 100 Continue

HTTP/1.1 500 INTERNAL SERVER ERROR
Server: Werkzeug/2.2.3 Python/3.7.16
Date: Tue, 19 Dec 2023 21:30:20 GMT
Content-Type: application/json
Content-Length: 403
Access-Control-Allow-Origin: *
Connection: close

In this case the CURLRequest class doesn't parse correctlly the headers

Steps to Reproduce

Make POST API with Flask 2.2.5 in debug mode and call it via CURLRequest

Expected Output

In this case status code should be 500 not 100

Anything else?

Just change this:

        if (strpos($output, 'HTTP/1.1 100 Continue') === 0) {

By this:

        while (strpos($output, 'HTTP/1.1 100 Continue' . $breakString) === 0) {

at line 392

For others who have the problem, actually I overwrite the class and specially the function send in my project and instanciate it via this function in Config\Service:

    public static function curlrequest($options = [], ResponseInterface $response = null, App $config = null, $getShared = false) {
        if ($getShared) {
            return static::getSharedInstance('curlrequest');
        }
        
        if(empty($config)) {
            $config = config(App::class);
        }
        return new CURLRequest($config, new URI((empty($options['baseURI']) ? null : $options['baseURI'])), $response, $options);
     }
@PhpEssential PhpEssential added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 19, 2023
@kenjis kenjis changed the title Bug: Multiple HTTP 100 return by API Bug: [CURLRequest] Multiple HTTP 100 return by API Dec 23, 2023
@kenjis
Copy link
Member

kenjis commented Dec 23, 2023

Your fix makes an existing test fail.

How about this?

--- a/system/HTTP/CURLRequest.php
+++ b/system/HTTP/CURLRequest.php
@@ -389,7 +389,7 @@ class CURLRequest extends OutgoingRequest
         // 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);
         }
 

@kenjis kenjis added the waiting for info Issues or pull requests that need further clarification from the author label Dec 25, 2023
@ping-yee
Copy link
Contributor

ping-yee commented Jan 26, 2024

Off topic, I have prepared the reproduction code and set up the flask server.
But how can I obtain the header information?

HTTP/1.1 100 Continue

HTTP/1.1 100 Continue

HTTP/1.1 500 INTERNAL SERVER ERROR
Server: Werkzeug/2.2.3 Python/3.7.16
Date: Tue, 19 Dec 2023 21:30:20 GMT
Content-Type: application/json
Content-Length: 403
Access-Control-Allow-Origin: *
Connection: close

@kenjis
Copy link
Member

kenjis commented Jan 26, 2024

$ curl -v https://codeigniter.com

@ping-yee
Copy link
Contributor

@kenjis I've reproduced the issue and the change can work.
I sent the PR #8466

@kenjis
Copy link
Member

kenjis commented Jan 27, 2024

@ping-yee Great!

@PhpEssential
Copy link
Author

Ok thanks ! In my case the flask call another api, maybe it's the way to reproduce

@kenjis kenjis removed the waiting for info Issues or pull requests that need further clarification from the author label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants