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 cURL - Parse header and Body #3261

Closed
demortx opened this issue Jul 10, 2020 · 1 comment
Closed

bug cURL - Parse header and Body #3261

demortx opened this issue Jul 10, 2020 · 1 comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@demortx
Copy link

demortx commented Jul 10, 2020

$continueStr = "HTTP/1.1 100 Continue\x0d\x0a\x0d\x0a";
if (strpos($output, $continueStr) === 0)
{
$output = substr($output, strlen($continueStr));
}
// Split out our headers and body
$break = strpos($output, "\r\n\r\n");
if ($break !== false)
{
// Our headers
$headers = explode("\n", substr($output, 0, $break));
$this->setResponseHeaders($headers);
// Our body
$body = substr($output, $break + 4);
$this->response->setBody($body);
}

FIX

$response_header_array = explode("\r\n\r\n", $output);
        $response_header  = '';
        for ($i = count($response_header_array) - 1; $i >= 0; $i--) {
            if (stripos($response_header_array[$i], 'HTTP/') === 0) {
                $response_header = $response_header_array[$i];
                break;
            }
        }
        if (!empty($response_header)){
            $headers = explode("\n", $response_header);
            $this->setResponseHeaders($headers);
            $this->response->setBody(end($response_header_array));
        }
Custom header parsing error
**BAD HEADER**

HTTP/1.1 100 Continue ---- **IS NOT** "HTTP/1.1 100 Continue\x0d\x0a\x0d\x0a" 
Server: ddos-guard
Set-Cookie: __ddg1=z177j4mLtqzC07v0zviU; Domain=.site.ru; HttpOnly; Path=/; Expires=Wed, 07-Jul-2021 15:13:14 GMT
				----- **FIRST** \r\n\r\n    Because of this, the headings fall in response to the body
HTTP/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
                                     ------- **TWO** \r\n\r\n     
<?xml version="1.0"?> <response><title>Update success! config</title><text>Successfully updated the project settings!</text><status>success</status></response> 
@demortx demortx changed the title Bag cURL bug cURL Jul 10, 2020
@demortx demortx changed the title bug cURL bug cURL - Parse hader and Body Jul 10, 2020
@demortx demortx changed the title bug cURL - Parse hader and Body bug cURL - Parse header and Body Jul 10, 2020
michalsn added a commit to michalsn/CodeIgniter4 that referenced this issue Jul 11, 2020
@michalsn michalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 11, 2020
@demortx
Copy link
Author

demortx commented Jul 11, 2020

Your fix works well, tested in live mode

@demortx demortx closed this as completed Jul 11, 2020
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

No branches or pull requests

2 participants