Skip to content

Instantly share code, notes, and snippets.

@diegok
Created October 10, 2011 01:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save diegok/1274441 to your computer and use it in GitHub Desktop.
Save diegok/1274441 to your computer and use it in GitHub Desktop.
Mojo::UserAgent with gzip support
#!/usr/bin/env perl
use 5.12.0;
use Mojo::UserAgent;
use Compress::Zlib;
my $ua = Mojo::UserAgent->new;
$ua->on( start => sub {
my ( $ua, $tx ) = @_;
$tx->req->headers->header('Accept-Encoding' => 'gzip');
$tx->on( finish => sub {
my $tx = shift;
$tx->res->body(Compress::Zlib::memGunzip($tx->res->body))
if $tx->res->headers->header('Content-Encoding')
&& $tx->res->headers->header('Content-Encoding') =~ /gzip/;
});
});
my $tx = $ua->get('https://metacpan.org/module/Mojolicious');
say $tx->res->body;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment