#!/usr/local/bin/perl use warnings; use strict; use LWP::UserAgent; use Gzip::Faster; my $ua = LWP::UserAgent->new (); my $url = 'http://www.lemoda.net/games/figlet/figlet.cgi?text=frog'; get ($ua, $url); $ua->default_header('Accept-Encoding' => 'gzip'); get ($ua, $url); exit; sub get { my ($ua, $url) = @_; my $response = $ua->get ($url); if ($response->is_success ()) { my $content_encoding = $response->header ('Content-Encoding'); my $text = $response->content; if ($content_encoding) { print "Content encoding is $content_encoding.\n"; if ($content_encoding eq 'gzip') { my $uncompressed = gunzip ($text); printf "Uncompressed from %d bytes to %d bytes.\n", length $text, length $uncompressed; $text = $uncompressed; } } else { print "Content encoding is not set.\n"; } print $text; } else { print STDERR "get '$url' failed: ", $response->status_line, "\n"; } }