anlutro / php-curl

Simple PHP curl wrapper class

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Curl response body too long.

gtinchev opened this issue · comments

Hi,

The response I should be getting is:
return Response::make('Received GC withdrawn hook for Invoice #' . $bill['id'] . ' but it has not been paid. Current status: ' . $invoice->status, 400);

That as a string looks like so:

Received GC withdrawn hook for Invoice #1234567890QWER but it has not been paid. Current status: UNPAID

Now, it correctly recognises the 100 Continue header, but it produces the following:

[2015-12-16 09:36:03] production.DEBUG: response:
[2015-12-16 09:36:03] production.DEBUG: HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Wed, 16 Dec 2015 09:36:03 GMT
Server: Apache
X-Powered-By: PHP/5.6.16
Cache-Control: no-cache
Set-Cookie: laravel_session=eyJpdiI6Imk3amdsWEdcL3NMS0lxKzdDVndRR1NRPT0iLCJ2YWx1ZSI6ImlHK3FrYUxrcHl0d2ttWWY2QUtzcVhETTh2YkVHcGNYUlNyVWRpMXpGVjVRaVZjMFwvTXdjY0dDalBMNHZkcXhLQ3NHdVhyeHBRZFl5M1ZIenI5czZkdz09IiwibWFjIjoiOGM1OWYwODI2OTM2MWVmM2RiM2UwNTUxY2Y4ZDVjYWMwZWM5NzEwNjFlNjcyOWFmYTA2YTVkMjFjNmI4MjI4MSJ9; expires=Wed, 16-Dec-2015 11:36:03 GMT; Max-Age=7200; path=/; httponly
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 80
Content-Type: text/html; charset=UTF-8

����� �0
�V���F.\�(�+�m_硇�����¡_���� ���(CSB����N(�K㚁���~��fR

If the response string is shorter - it parses it correctly and result is readable.

Looking forward to hearing from you.

Many thanks,
Georgi

Hi,

The problem appears to be that when the body is too long, it gets gzipped, in order to save bandwidth.
I forgot to set additional options to the ch.
It would be nice to have this as a default:

curl_setopt($ch,CURLOPT_ENCODING , "gzip");

Thanks,
Georgi

I don't know enough to say for sure if setting that by default would cause any issues - but maybe it's possible to read the Content-Encoding header and set the option if it equals "gzip".

Exactly!
But, it doesn't cause any problems with small body content, either.
Just thought I'd give you a heads up. :)

I think I'll leave this "feature" out for now, I'd rather avoid adding complexity and sticking close to what regular PHP curl behaviour is. It's odd that your web server is serving you gzipped content when you've not explicitly asked for it, it shouldn't do that. If you do $curl->setOption(CURLOPT_ENCODING, 'gzip'), that will send the Accept-Encoding: gzip header as well as tell curl to automatically decode an encoded response.