WWW-Mechanize-GZip-0.12/0000755000004100000410000000000011220404104014704 5ustar www-datawww-dataWWW-Mechanize-GZip-0.12/Makefile.PL0000744000004100000410000000107710714552276016711 0ustar www-datawww-datause strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'WWW::Mechanize::GZip', AUTHOR => 'Peter Giessner ', VERSION_FROM => 'lib/WWW/Mechanize/GZip.pm', ABSTRACT_FROM => 'lib/WWW/Mechanize/GZip.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'Compress::Zlib' => 0, 'WWW::Mechanize' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'WWW-Mechanize-GZip-*' }, ); WWW-Mechanize-GZip-0.12/README0000744000004100000410000000047510714552276015620 0ustar www-datawww-dataWWW-Mechanize-GZip INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install COPYRIGHT AND LICENCE Copyright (C) 2007 Peter Giessner This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. WWW-Mechanize-GZip-0.12/lib/0000755000004100000410000000000011220404104015452 5ustar www-datawww-dataWWW-Mechanize-GZip-0.12/lib/WWW/0000755000004100000410000000000011220404105016137 5ustar www-datawww-dataWWW-Mechanize-GZip-0.12/lib/WWW/Mechanize/0000755000004100000410000000000011220404105020042 5ustar www-datawww-dataWWW-Mechanize-GZip-0.12/lib/WWW/Mechanize/GZip.pm0000744000004100000410000000632511220404356021270 0ustar www-datawww-data=head1 NAME WWW::Mechanize::GZip - tries to fetch webpages with gzip-compression =head1 VERSION Version 0.10 =head1 SYNOPSIS use WWW::Mechanize::GZip; my $mech = WWW::Mechanize::GZip->new(); my $response = $mech->get( $url ); print "x-content-length (before unzip) = ", $response->header('x-content-length'); print "content-length (after unzip) = ", $response->header('content-length'); =head1 DESCRIPTION The L module tries to fetch a URL by requesting gzip-compression from the webserver. If the response contains a header with 'Content-Encoding: gzip', it decompresses the response in order to get the original (uncompressed) content. This module will help to reduce bandwith fetching webpages, if supported by the webeserver. If the webserver does not support gzip-compression, no decompression will be made. This modules is a direct subclass of L and will therefore support any methods provided by L. The decompression is handled by L::memGunzip. There is a small webform, you can instantly test, whether a webserver supports gzip-compression on a particular URL: L =head2 METHODS =over 2 =item prepare_request Adds 'Accept-Encoding' => 'gzip' to outgoing HTTP-headers before sending. =item send_request Unzips response-body if 'content-encoding' is 'gzip' and corrects 'content-length' to unzipped content-length. =back =head1 SEE ALSO L L =head1 AUTHOR Peter Giessner C =head1 LICENCE AND COPYRIGHT Copyright (c) 2007, Peter Giessner C. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut package WWW::Mechanize::GZip; our $VERSION = '0.12'; use strict; use warnings; use Compress::Zlib (); use base qw(WWW::Mechanize); ################################################################################ sub prepare_request { my ($self, $request) = @_; # call baseclass-method to prepare request... $request = $self->SUPER::prepare_request($request); # set HTTP-header to request gzip-transfer-encoding at the webserver $request->header('Accept-Encoding' => 'gzip'); return ($request); } ################################################################################ sub send_request { my ($self, $request, $arg, $size) = @_; # call baseclass-method to make the actual request my $response = $self->SUPER::send_request($request, $arg, $size); # check if response is declared as gzipped and decode it if ($response && defined($response->headers->header('content-encoding')) && $response->headers->header('content-encoding') eq 'gzip') { # store original content-length in separate response-header $response->headers->header('x-content-length', length($response->{_content})); # decompress ... $response->{_content} = Compress::Zlib::memGunzip(\($response->{_content})); # store new content-length in response-header $response->{_headers}->{'content-length'} = length($response->{_content}); } return $response; } 1; __END__WWW-Mechanize-GZip-0.12/t/0000755000004100000410000000000011220404103015146 5ustar www-datawww-dataWWW-Mechanize-GZip-0.12/t/00-load.t0000744000004100000410000000025210714552276016515 0ustar www-datawww-data#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'WWW::Mechanize::GZip' ); } diag( "Testing WWW::Mechanize::GZip $WWW::Mechanize::GZip::VERSION, Perl $], $^X" ); WWW-Mechanize-GZip-0.12/t/boilerplate.t0000744000004100000410000000233110714552276017663 0ustar www-datawww-data#!perl -T use strict; use warnings; use Test::More tests => 3; sub not_in_file_ok { my ($filename, %regex) = @_; open my $fh, "<", $filename or die "couldn't open $filename for reading: $!"; my %violated; while (my $line = <$fh>) { while (my ($desc, $regex) = each %regex) { if ($line =~ $regex) { push @{$violated{$desc}||=[]}, $.; } } } if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } } not_in_file_ok(README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, ); not_in_file_ok(Changes => "placeholder date/time" => qr(Date/time) ); sub module_boilerplate_ok { my ($module) = @_; not_in_file_ok($module => 'the great new $MODULENAME' => qr/ - The great new /, 'boilerplate description' => qr/Quick summary of what the module/, 'stub function definition' => qr/function[12]/, ); } module_boilerplate_ok('lib/WWW/Mechanize/GZip.pm'); WWW-Mechanize-GZip-0.12/t/pod.t0000744000004100000410000000021410714552276016141 0ustar www-datawww-data#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); WWW-Mechanize-GZip-0.12/t/pod-coverage.t0000744000004100000410000000025410714552276017736 0ustar www-datawww-data#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); WWW-Mechanize-GZip-0.12/META.yml0000744000004100000410000000000010714552276016171 0ustar www-datawww-dataWWW-Mechanize-GZip-0.12/.cvsignore0000744000004100000410000000015110714552276016727 0ustar www-datawww-datablib* Makefile Makefile.old Build _build* pm_to_blib* *.tar.gz .lwpcookies WWW-Mechanize-GZip-* cover_db WWW-Mechanize-GZip-0.12/MANIFEST0000744000004100000410000000023510714552276016063 0ustar www-datawww-dataChanges MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/WWW/Mechanize/GZip.pm t/00-load.t t/boilerplate.t t/pod-coverage.t t/pod.t WWW-Mechanize-GZip-0.12/Changes0000744000004100000410000000052511220404302016202 0ustar www-datawww-dataRevision history for WWW-Mechanize-GZip 0.12 2009-06-24 - fixed warning on undefined 'content-encoding' - thanks to Edward Smirnov 0.11 2009-06-16 - added comments to pass POD-Coverage - thanks to Jesse Vincent - added 'use warnings;' - thanks to Jesse Vincent too 0.10 2007-02-18 First version.