Created
November 10, 2011 21:34
-
-
Save kraih/1356311 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojo::Base -strict; | |
use Mojo::UserAgent; | |
use Mojo::Util 'sha1_sum'; | |
my $ua = Mojo::UserAgent->new; | |
# Decorate every transaction in "start" event | |
$ua->on(start => sub { | |
my ($ua, $tx) = @_; | |
# First "read" event to show chunk size | |
$tx->res->content->on(read => sub { | |
my ($content, $chunk) = @_; | |
say 'Chunk size: ', length($chunk), ' bytes'; | |
}); | |
# Second "read" event to generate SHA1 sum for chunk | |
$tx->res->content->on(read => sub { | |
my ($content, $chunk) = @_; | |
say 'Chunk SHA1: ', sha1_sum($chunk); | |
}); | |
}); | |
# Normal request | |
my $tx = $ua->get('mojolicio.us'); | |
say 'Content size: ', length($tx->res->body), ' bytes'; | |
say 'Content SHA1: ', sha1_sum($tx->res->body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment