Skip to content

bug cURL - Parse header and Body #3261

Closed
@demortx

Description

@demortx

$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> 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions