Checking gzip/deflate server responses with CURL

Nginx and Apache can gzip/deflate content as it is leaving the server, which decreases the amount of data that has to cross the wire and therefor speeds up communication with the server. This can’t be turned on for all requests, however, because not all clients know how to decompress the responses. Most commonly, the ‘Accept-Encoding’ header of the HTTP 1.1 specification is sent with a value of ‘gzip,deflate’ to request compressed responses.

Testing this compression can be a little tricky, because often clients handle it so seamlessly you may not know it ever happens. Additionally, server configuration may further complicate testing, compressing data for some requests and not others, i.e. Nginx’s gzip_http_version directive, which may only serve compressed data for HTTP 1.1 requests.

Curl provides a simple tool for checking server responses.

First, a few curl arguments that will come in handy:

  • “–silent” prevents curl from showing progress meter
  • “–write-out ‘size_download=%{size_download}\n’” instructs curl to print out the download size
  • “–output” instructs curl to throw away the output, sending it to /dev/null

Using these arguments, we can make a simple request for a path on the server:

ns:~ nick$ curl --silent --write-out "size_download=%{size_download}\n" --output /dev/null

Here, you can the response was 31032 bytes. Next up, lets make the same request, this time adding the Accept-Encoding header to ask for compressed content.

ns:~ nick$ curl --silent -H "Accept-Encoding: gzip,deflate" --write-out "size_download=%{size_download}\n" --output /dev/null

Nice! This downloaded only 2553 bytes of data, so it the data is definitely being compressed. Up next, lets try making the request a third time, now making the request a HTTP1.0 request.

ns:~ nick$ curl --silent --http1.0 -H "Accept-Encoding: gzip,deflate" --write-out "size_download=%{size_download}\n" --output /dev/null

This response was not request, which makes sense when using Nginx with the gzip_http_version set to ’1.1′. Additionally, this method can easily be applied to POST requests if you add the appropriate arguments to curl.


One thought on “Checking gzip/deflate server responses with CURL

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>