How to test if a webserver is using compression

Was in a situation where I wanted to verify that my cdn is compressing for me, but that my origin is not.

Background on the curl flags, “-I” tells it to only request the headers not the full page. “-H” passes it request headers. The “Accept-Encoding” header tells the webserver that its OK by the client if it compresses the response. The “Host” header is… well, the host header. If you’re not sure what that means then get off my blog.

First off test the CDN:

[jim@brandt ~]$ curl -I -H "Accept-Encoding: gzip,deflate" -H "Host: www.mycorp.com" http://www.mycorp.com/foo/bar.html
HTTP/1.1 200 OK
Server: Apache/2.2.8 (Unix)
Content-Type: text/html
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 43593
Date: Mon, 22 Feb 2010 15:28:58 GMT
Connection: keep-alive

Notice the “Content-Encoding: gzip” header in the response. That means you got a gzip’d response, compression is in effect.

Now skip the CDN and test origin directly:

[jim@brandt ~]$ curl -I -H "Accept-Encoding: gzip,deflate" -H "Host: www.mycorp.com" http://origin.mycorp.com/foo/bar.html
HTTP/1.1 200 OK
Date: Mon, 22 Feb 2010 15:12:32 GMT
Server: Apache/2.2.8 (Unix)
Content-Type: text/html

The lack of a “Content-Encoding” header means its *not* compressed.

Leave a Reply