Here's a snippet of code I have used to process
deflated HTTP responses. It would be great if this
processing could be handled somewhere in the guts of
LWP!
sub inflateBody {
my ($body_ref) = @_;
my $body = $$body_ref;
my $result = undef;
my $deflated_length = length($body);
my $i = inflateInit( -WindowBits => -15 ) or die
"Cannot create an inflation stream\n" ;
($result, my $status) = $i->inflate($body);
if ($status == Z_OK or $status == Z_STREAM_END) {
my $inflated_length = length($result);
my $compression_ratio = int((1 -
$deflated_length/$inflated_length) * 100);
print "\nContent-length after inflate =
$inflated_length savings = $compression_ratio%\n\n";
#decode_entities($result); # get rid of HTML
entities ("&" etc.)
#if (length($result) <= 1024) { # only print the
small ones (redirects)
# print "\nBody =\n$result\n";
#}
} else {
print "\nInflation failed: status = $status\n";
print "\nBody length after failed inflate =
",length($result),"\n";
print "\n1st 40 body char codes after failed inflate
=\n";
for (my $j=0;$j<39;$j++) {
print ord(substr($body,$j,1)), " ";
}
print "\n";
if (defined($result)) { print "\nInflated body =
$result\n";}
}
return $result;
}