Objective: Check if web server supports the serving of gzipped content.
We can use curl to test if a apache or nginx web server is configured to server gzipped content. The "Accept-Encoding: gzip,deflate"
request header is used to inform the server that the client accepts gzip encoding. If the server supports gzip encoding and if response header from the web server indicates “Content-Encoding: gzip”, then the content is gzipped.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$ curl -svo /dev/null -H "Accept-Encoding: gzip,deflate" stackpointer.io * Rebuilt URL to: stackpointer.io/ * Hostname was NOT found in DNS cache * Trying 104.27.137.56... * Connected to stackpointer.io (104.27.137.56) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.35.0 > Host: stackpointer.io > Accept: */* > Accept-Encoding: gzip,deflate > < HTTP/1.1 200 OK < Date: Tue, 03 May 2016 09:08:32 GMT < Content-Type: text/html < Content-Length: 13271 < Connection: keep-alive < Set-Cookie: __cfduid=d6715588427f12aa8979fc30f9576ee661462266512; expires=Wed, 03-May-17 09:08:32 GMT; path=/; domain=.digitalinternals.com; HttpOnly < Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT < Expires: Tue, 03 May 2016 10:00:57 GMT < Pragma: public < Cache-Control: max-age=3600, public < Etag: 6d7e9854d8152b5474c213c405236884 < Content-Encoding: gzip < Vary: Accept-Encoding < Accept-Ranges: bytes < X-Varnish: 1836835174 1836835064 < Age: 455 < X-Cache: HIT * Server cloudflare-nginx is not blacklisted < Server: cloudflare-nginx < CF-RAY: 29d291a7f01d11e9-SJC < { [data not shown] * Connection #0 to host stackpointer.io left intact |
If you are only interested in the “Accept-Encoding
” and “Content-Encoding
” headers, you can use the following syntax to filter the output.
1 2 3 |
$ curl -svo /dev/null -H "Accept-Encoding: gzip,deflate" stackpointer.io 2>&1 | grep -i "encoding" > Accept-Encoding: gzip,deflate < Content-Encoding: gzip |
If your server is configured for gzipped content, but if it’s not working as expected, check for the presence of the “Via
” request header. This header is usually inserted by proxies. The “Via
” header can disable gzip compression unless the web server is configured to compress proxied requests. On Nginx, this is controlled by the “gzip_proxied
” parameter.