Closed victorpal closed 5 years ago
@victorpal I've tested it and I don't know how it is possible that you are getting wrong response headers size (at least this is what you are saying). I've checked the code and we get it from curl, before any modifications, so there is no way it's invalid (unless there is a bug in curl).
Are you sure that in your case Transfer-Encoding: chunked
is removed in line (486):
$responseHeaders = preg_replace("/Transfer-Encoding:\s*chunked\\r\\n/i", '', $responseHeaders);
@webimpress Yes i'm sure that is removed (var_dumping $responseHeaders results in what i put in the message below "$responseHeaders is:"), but doesn't matter because $this->response = substr_replace($this->response, $responseHeaders, 0, $responseHeaderSize); that substr_replace doesn't remove the Transfer-Encoding because $responseHeaderSize is 405 and doesn't reach that part of the header to replace it. Thanks.
@victorpal yes, I've seen your dumps and it's impossible as:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Date: Tue, 06 Aug 2019 12:45:19 GMT
Expires: Tue, 06 Aug 2019 12:45:19 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: quic=":443"; ma=2592000; v="46,43,39"
Connection: close
Transfer-Encoding: chunked
is 389 chars and 12 line breaks
Also your dump of $responseHeaders
is incomplete as it finishes on "Connection" not "Connection: close" what I would expect.
Better if you provide failing test case (unit test), then it will be much easier to to track down the issue and resolve it.
$responseHeaders is incomplete because line 482 $responseHeaders = substr($this->response, 0, $responseHeaderSize); $this->reponse is: HTTP/1.0 200 Connection established
HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Content-Encoding: gzip Date: Fri, 27 Sep 2019 12:11:23 GMT Expires: Fri, 27 Sep 2019 12:11:23 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Alt-Svc: quic=":443"; ma=2592000; v="46,43",h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000 Connection: close Transfer-Encoding: chunked
$responseHeaderSize is 456 and $responseHeaders is what u know. I know that counting the chars seems that doesn't fit, but the substr method does that, i guess its something about the linebreaks.
@victorpal I've done many testes again, through the proxy, with different curl configurations etc and always I am getting the correct headers length.
Please provide your curl configuration, proxy etc, whatever what can help replicate the issue.
Seems to be exactly the same issue as https://github.com/zendframework/zend-http/issues/24 as I have curl 7.26.0
@victorpal Thanks for the update!
as I have curl 7.26.0
wooo... that's old! 24 May 2012 https://curl.haxx.se/changes.html#7_26_0
I guess, as it is bug in external library and it's very old bug already fixed, this ticket is going to be closed as "won't fix". I need to have a closer look to make a decision, but I would suggest updating curl.
Notes to documentation has been added. Thanks, @victorpal!
When submitting the form with Adapter Curl you have
// cURL automatically decodes chunked-messages, this means we have to
// disallow the Zend\Http\Response to do it again.
$responseHeaders = preg_replace("/Transfer-Encoding:\s*chunked\\r\\n/i", '', $responseHeaders);
which is OK but in line 503$this->response = substr_replace($this->response, $responseHeaders, 0, $responseHeaderSize);
$this->response (the first parameter of substr) is:
HTTP/1.0 200 Connection established
HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Content-Encoding: gzip Date: Tue, 06 Aug 2019 12:45:19 GMT Expires: Tue, 06 Aug 2019 12:45:19 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Alt-Svc: quic=":443"; ma=2592000; v="46,43,39" Connection: close Transfer-Encoding: chunked
� ��RPP.MNN-.V�RHK�)N�����&秤�ģ�B@�������]�LJiANfrbI�P�� g �I
$responseHeaders is:
HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Content-Encoding: gzip Date: Tue, 06 Aug 2019 12:45:19 GMT Expires: Tue, 06 Aug 2019 12:45:19 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Alt-Svc: quic=":443"; ma=2592000; v="46,43,39" Connection
and $responseHeaderSize = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE); is 405
which results in $this->result =
HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Content-Encoding: gzip Date: Tue, 06 Aug 2019 12:45:19 GMT Expires: Tue, 06 Aug 2019 12:45:19 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Alt-Svc: quic=":443"; ma=2592000; v="46,43,39" Connection: close Transfer-Encoding: chunked
� ��RPP.MNN-.V�RHK�)N�����&秤�ģ�B@�������]�LJiANfrbI�P�� g �I
so in the header "Transfer-Encoding: chunked" is still there and then i hit an exception:
exception 'Zend\Http\Exception\RuntimeException' with message 'Error parsing body - doesn't seem to be a chunked message' in zendframework/zend-http/src/Response.php:533