David,

In my WWW::Mech sub-class, I'm not actually modifying the response.

WWW::Mech extracts the content out into its own variable, thus I do the same
for the uncompressed content. If you happen to ask for WWW::Mech's response
object ($a->response()) then you'll get the compressed data and you'll have
to deal with that on your own.

I'm not really sure how you'd have to handle it in LWP at this point. I'd
prefer this be adapted in such a way that you wouldn't have to mess with the
original response data.

-Brian 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 02, 2003 1:57 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: RFC: WWW::Mechanize::Compress or LWP patch?

Don't you also need to adjust the content-length header
to match the new (uncompressed) content? 

---
David Carter
[EMAIL PROTECTED]




On Tue, 2 Dec 2003 13:37:06 -0400, "Brian Cassidy"
wrote:

> 
> Hi All,
> 
> Today I cooked up a little bit of code [1] to give
> WWW::Mechanize the
> ability to handle compressed content (gzip and
> deflate). I forwarded it over
> to Andy for his comments and he thought that maybe it
> would be best if this
> code was adapted for use directly in LWP.
> 
> I would tend to agree since everything is handled
> behind the scenes.
> + If Compress::Zlib isn't available, we forgo the
> "Accept_encoding" headers
> + It makes sure the response is compressed before
> trying to uncompress
> 
> The only (freak) edge case would be if you get a
> response that was encoded
> and Compress::Zlib isn't available (thus it
croak()s). 
> 
> There could be considerable bandwidth savings if LWP
> users were able to get
> compressed content by default (without even knowing it
> :). Although I guess
> therein hides the problem where we force people to
> accept compressed
> content.
> 
> Comments?
> 
> -Brian Cassidy ( [EMAIL PROTECTED] )
> 
> [1]
> 
> package WWW::Mechanize::Compress;
> 
> use strict;
> use warnings FATAL => 'all';
> use vars qw( $VERSION $HAS_ZLIB );
> $VERSION = '0.01';
> 
> use base qw( WWW::Mechanize );
> use Carp qw( carp croak );
> 
> BEGIN {
>       $HAS_ZLIB = 1 if defined eval "require
> Compress::Zlib;";
> }
> 
> sub _make_request {
>       my $self    = shift;
>       my $request = shift;
> 
>       $request->header( Accept_encoding => 'gzip; deflate'
)
> if $HAS_ZLIB;
> 
>       my $response = $self->SUPER::_make_request( $request,
> @_ );
> 
>       if ( my $encoding = $response->header(
> 'Content-Encoding' ) ) {
>               croak 'Compress::Zlib not found. Cannot uncompress
> content.'
> unless $HAS_ZLIB;
> 
>               $self->{ uncompressed_content } =
> Compress::Zlib::memGunzip(
> $response->content ) if $encoding =~ /gzip/i;
>               $self->{ uncompressed_content } =
> Compress::Zlib::uncompress( $response->content ) if
> $encoding =~ /deflate/i;
>       }
> 
>       return $response;
> }
> 
> sub content {
>       my $self = shift;
> 
>       return $self->{ uncompressed_content } || $self->{
> content };
> }
> 
> 1;
> 
> 
> http://www.gordano.com - Messaging for educators.


http://www.gordano.com - Messaging for educators.

Reply via email to