WWW::CheckGzip - check web pages for correct gzipping of content
# This example demonstrates use with the Test::More testing framework.
my $wc = WWW::CheckGzip->new (\& mycheck);
my ($ok, $message) = @_;
ok ($ok, $message);
ok 1 - successfully got compressed http://www.piedpiper.com
ok 2 - got content encoding
ok 3 - content encoding is gzip
ok 4 - http://www.piedpiper.com correctly gzipped
ok 5 - compression made it smaller
ok 6 - successfully got uncompressed http://www.piedpiper.com
ok 7 - Did not get content encoding
ok 8 - http://www.piedpiper.com not gzipped when requesting ungzipped
(This example is included as synopsis.pl 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:
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.
When sent a request with an Accept-Encoding header containing the string gzip, the web page responds with a content encoding header.
The content encoding header of the response is gzip.
The content of the web page's response is in the gzip format. This is checked using "gunzip" in Gzip::Faster.
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.
The web page is retrievable without an Accept-Encoding header set.
The web page does not send a gzip header if the Accept-Encoding header is not set.
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.
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,
# clean up if necessary as follows
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.
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.
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.
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.
A very simple demonstration of compression using CGI (the common gateway interface) and Gzip::Faster.
Similar to the above, but for the Go language.
Another Perl example, this time using the IO::Compress::Gzip module instead of Gzip::Faster.
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: http://prepan.org/module/nYdTCdrkEGF. 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 https://www.lemoda.net/compression/lwp-use-gzip/index.html.
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, <firstname.lastname@example.org>
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.
To install WWW::CheckGzip, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.