#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $url = shift || "";
$url = "http://localhost:8080/$url" unless $url =~ /:/;
my $tot = 0;
my $ct_len;
my $ua = LWP::UserAgent->new;
my $res = $ua->request(HTTP::Request->new("GET", $url), \&data);
sub data {
my ($data, $response) = @_;
my $len = length $data;
$tot += $len;
print "Got $len bytes";
unless ($ct_len) {
$ct_len = $response->header("Content-Length");
}
if ($ct_len) {
printf " (%.1f%% done)", $tot/$ct_len*100.0;
}
print "\n";
}
print $res->as_string;