WWW::CheckGzip - check web pages for correct gzipping of content


    # This example demonstrates use with the Test::More testing framework.
    use Test::More;
    use WWW::CheckGzip;
    my $wc = WWW::CheckGzip->new (\& mycheck);
    $wc->check ('');
    done_testing ();
    sub mycheck
        my ($ok, $message) = @_;
        ok ($ok, $message);

produces output

    ok 1 - successfully got compressed
    ok 2 - got content encoding
    ok 3 - content encoding is gzip
    ok 4 - correctly gzipped
    ok 5 - compression made it smaller
    ok 6 - successfully got uncompressed
    ok 7 - Did not get content encoding
    ok 8 - not gzipped when requesting ungzipped

(This example is included as in the distribution.)


This documents version 0.05 of WWW::CheckGzip corresponding to git commit c2e1c0b7f8722fa48778c1027ae79c3019348a0b released on Wed Oct 4 11:01:08 2017 +0900.


This module offers a way to check a web page for correct gzip compression. It tests the following, in the order given:

Page OK with compression

The web page is retrievable with an Accept-Encoding header set.

If the page is not retrievable, "check" calls the test callback, then returns and does no further actions.

Header OK

When sent a request with an Accept-Encoding header containing the string gzip, the web page responds with a content encoding header.

Header is gzip

The content encoding header of the response is gzip.

Content is in gzip format

The content of the web page's response is in the gzip format. This is checked using "gunzip" in Gzip::Faster.

Content is smaller

The size of the uncompressed content of the web page is larger than it is when compressed. This test will fail, for example, if gzip encoding is wrongly used to compress images or extremely small web pages.

Page OK without compression

The web page is retrievable without an Accept-Encoding header set.

Response has no gzip header

The web page does not send a gzip header if the Accept-Encoding header is not set.

Content is not compressed

The web page does not gzip compress the content when Accept-Encoding header is not sent. This is checked using "gunzip" in Gzip::Faster.



    my $wc = WWW::CheckGzip->new (\& test_sub);

Create a new object. The argument is a code reference to a subroutine of your choosing. The subroutine should take two arguments, a boolean $ok indicating whether the test was successful, and a string $message containing a descriptive message about the test. See "SYNOPSIS" for an example using the Test::More testing framework.

If you do not supply a function, a default function which prints the results to standard output is used. The return value is a blessed WWW::CheckGzip object.


    $wc->check ('');

Check the URL given as the argument. The tests call the callback supplied to "new". There is no return value. If no URL is supplied, a warning is printed and the function returns.


In order to not cause problems for testers, this module does not attempt to connect to the internet during its tests. To run the module's tests with a real web site, set the environment variable WEBSITE to a real website you know to be well-behaved with regards to gzip compression. For example, on a Unix-like system,

    export WEBSITE=
    make test
    # clean up if necessary as follows
    export WEBSITE=

will cause the module to attempt to connect to the given web site and check its compression.

The tests will fail if the web site does not use gzip correctly, so using your local web server may cause test failures which are not this module's fault.



This is used to report user errors.

"gunzip" in Gzip::Faster

This is used to test whether the page content is in the gzip format or not.


This is used to retrieve the web page. Until version 0.04, LWP::UserAgent was used.


GET only

As of version 0.05, the module currently only does GET requests.


A script checkgzip in the distribution checks web pages given to it on the command line:


"No output" indicates success, so that this can be used by, for example cron jobs.


CPAN Modules

I'm not aware of any other module which explicitly checks for gzip-related problems from a web page.


This module retrieves gzip content from web pages.

About compression on the web


Some scripts by the author of this module related to compression of static content (content which does not change with each request, such as JavaScript files).

Compressing CGI output with Perl and Gzip::Faster

A very simple demonstration of compression using CGI (the common gateway interface) and Gzip::Faster.

Gzip handler in Go

Similar to the above, but for the Go language.

Compressing CGI output with Perl

Another Perl example, this time using the IO::Compress::Gzip module instead of Gzip::Faster.

Online gzip checkers

By the author of WWW::Mechanize::GZip.

Online AJAX checker with noises and colours.

Another AJAX checker.

Google PageSpeed Insights has compression checking as one of its facilities. For whatever reason it doesn't actually tell you if the page is compressed correctly, but only lets you know if there is a problem.


I created this module to have a simple command-line script or module for checking that gzip compression of my own web pages was working correctly.

On 6 March 2017, I suggested the module on PrePAN: Unfortunately it didn't get any responses. Initially I was planning to fork "WWW::Mechanize::GZip", and the old commits in the github repository contain some code from that module.

On 16 August 2017 I completely rewrote the module to remove the "WWW::Mechanize::GZip" parts and released version 0.01 to CPAN. The methodology the module used was based on my web page

On 1 October 2017, for version 0.04, I changed from LWP::UserAgent to HTTP::Tiny at the suggestion of a blog commentator.


Ben Bullock, <>


This package and associated files are copyright (C) 2017 Ben Bullock.

You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.