
wickedxter
User
Jan 24, 2012, 9:53 AM
Post #2 of 2
(669 views)
|
|
Re: [hostage] Watching UserAgent progress
[In reply to]
|
Can't Post
|
|
from lwp::useragent module (its alomost at the bottom of the page.)
response_data => sub { my($response, $ua, $h, $data) = @_; ... } This handler is called for each chunk of data received for the response. The handler might croak to abort the request. This handler needs to return a TRUE value to be called again for subsequent chunks for the same request. response_done => sub { my($response, $ua, $h) = @_; ... } The handler is called after the response has been fully received, but before any redirect handling is attempted. The handler can be used to extract information or modify the response. http://search.cpan.org/~gaas/libwww-perl-6.03/lib/LWP/UserAgent.pm found this in the lwpcookbook
use LWP::UserAgent; $ua = LWP::UserAgent->new; $URL = 'ftp://ftp.unit.no/pub/rfc/rfc-index.txt'; my $expected_length; my $bytes_received = 0; my $res = $ua->request(HTTP::Request->new(GET => $URL), sub { my($chunk, $res) = @_; $bytes_received += length($chunk); unless (defined $expected_length) { $expected_length = $res->content_length || 0; } if ($expected_length) { printf STDERR "%d%% - ", 100 * $bytes_received / $expected_length; } print STDERR "$bytes_received bytes received\n"; # XXX Should really do something with the chunk itself # print $chunk; }); print $res->status_line, "\n";
(This post was edited by wickedxter on Jan 24, 2012, 9:56 AM)
|