Gzip Content Encoding in Guzzle 6
Guzzle 6 removes the Content-Encoding header by default. (See: https://github.com/guzzle/guzzle/blob/master/src/Handler/StreamHandler.php#L170) This is a bit annoying if you want to check whether a website uses Gzip or not.
If you pass a header and a decode_content option to the client, the Content-Encoding header won't be removed:
<?php $client = new Client([ headers' => [ 'Accept-Encoding' => 'gzip', ], 'decode_content' => null, ]); $headers = $client->head('uri')->getHeaders(); var_dump($headers);
You can verify this by sending a raw cURL request, e.g.:
curl -L -I -H 'Accept-Encoding: gzip,deflate' http://www.google.com
Important: if you don't get valid response headers back, but you are sure gzip is enabled, it might be that the module 'mod_headers' (Apache) isn't enabled.