1

This code:

$headersSize     = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$responseHeaders = substr($response, 0, $headersSize);
$responseBody    = substr($response, $headersSize);

return incorrect size (strlen) of headers, e.g. here:

...
Pragma: no-cache
Set-Cookie: foo=bar; pat

 ---- curl want split here ---- 

h=/
Access-Control-Allow-Origin: *

<!DOCTYPE html ...

Response can have multiple headers (redirections, continue, etc.). And ofcourse like this isnt work:

list($header, $body) = explode("\r\n\r\n", $response, 2);

How to correct determine size of headers?

5
  • Might be related to this: bugs.php.net/bug.php?id=63894&edit=1 Please include the PHP and CURL versions you're using. Commented Jan 12, 2016 at 12:28
  • sourceforge.net/p/curl/bugs/1204 That fix was commit bc6037e which went into curl 7.30.0 Commented Jan 12, 2016 at 12:30
  • @AlexanderMP php5.3, but this is required for my application (very old legacy code) and I must fix only without upgrade php version or something. Commented Jan 12, 2016 at 12:32
  • 1
    Well, it's a bug. Any fix after this bug will be unreliable. Knowing how it works, you can just manually add/subtract to the length of the header by a specific amount, just see how much it's missing. Or if the proxy is used only for HTML, then you can manually parse the string until you get a line that starts with a HTML tag, which is where your header ends. Sorry, but I don't see a reliable solution other than to fix this bug at the source. If you can, you can just update curl, libcurl or whatever. Or you can pull that version from git, fix this bug, recompile, if you're version-sensible. Commented Jan 12, 2016 at 12:39
  • @AlexanderMP write your comments as answer. Commented Jan 12, 2016 at 12:52

1 Answer 1

1

Might be related to this: https://bugs.php.net/bug.php?id=63894&edit=1 or http://sourceforge.net/p/curl/bugs/1204

That fix was commit bc6037e which went into curl 7.30.0

Anyway, it's a bug. Any fix after this bug will be unreliable.

Knowing how it works, you can just manually add/subtract to the length of the header by a specific amount, just see how much it's missing.

Or if the proxy is used only for HTML, then you can manually parse the string until you get a line that starts with a HTML tag, which is where your header ends.

Sorry, but I don't see a reliable solution other than to fix this bug at the source. If you can, you can just update curl, libcurl or whatever. Or you can pull that version from git, fix this bug, recompile, if you're version-sensible.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmmm!! Proxy server always return first header "HTTP/1.0 200 Connection established"? I can try substract this length for correctly slit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.