Blog

03/06/2019

Linux / Unix Curl: Find Out If a Website Is Using Gzip / Deflate



How do I find out if a web-page is gzipped or compressed using Unix command line utility called curl? How do I make sure mod_deflate or mod_gzip is working under Apache web server?

When content is compressed, downloads are faster because the files are smaller—in many cases, less than a quarter the size of the original. This is very useful for JavaScript and CSS files (including html), faster downloads translates into faster rendering of web pages for end-user. The mod_deflate or mod_gzip Apache module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network. Most modern web browser support this feature. You can use the curl command to find out if a web page is gzipped or not using the the following simple syntax.

Syntax

The syntax is:

curl -I -H 'Accept-Encoding: gzip,deflate' http://example.com

OR

curl -s -I -L -H 'Accept-Encoding: gzip,deflate' http://example.com

Where,

  1. -s – Don’t show progress meter or error messages.
  2. -I – Work on the HTTP-header only.
  3. -H 'Accept-Encoding: gzip,deflate' – Send extra header in the request when sending HTTP to a server.
  4. -L – f the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place.
  5. http://example.com – Your URL, it can start with http or https.

Examples

Type the following command:

curl -I -H 'Accept-Encoding: gzip,deflate' http://sxi.io/

Sample outputs:

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 06 Nov 2012 18:59:26 GMT
Content-Type: text/html
Connection: keep-alive
X-Whom: l2-com-cyber
Vary: Cookie
Vary: Accept-Encoding
Last-Modified: Tue, 06 Nov 2012 18:51:58 GMT
Cache-Control: max-age=152, must-revalidate
Content-Encoding: gzip
X-Galaxy: Andromeda-1
X-Origin-Type: DynamicViaDAL

Curl command accept-encoding gzip bash test function

Create a bash shell function and add to your ~/.bashrc file:

gzipchk(){ curl -I -H 'Accept-Encoding: gzip,deflate' "$@" | grep --color 'Content-Encoding:'; }

OR use the silent mode to hide progress bar:

gzipchk(){ curl -sILH 'Accept-Encoding: gzip,deflate' "$@" | grep --color 'Content-Encoding:'; }

Save and close the file. Reload ~/.bashrc file, run:
$ source ~/.bashrc file
Test the gzipchk() as follows:
$ gzipchk sxi.io
gzipchk http://www.redhat.com

Sample outputs:

Fig.01: Linux curl deflate gzip test in action

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

20/08/2019

Start your Bitcoin Exchange with our Software

Start your Bitcoin Exchange with our Software Setup your white label bitcoin exchange right away. Or create your own cryptocurrency using...
14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....