DaTa! has asked for the wisdom of the Perl Monks concerning the following question:
I want LWP::UserAgent to log the following information:
requested uri, time it took to fetch, content length and header length.
The following code works unless somebody uses :content_cb, in this case $content_length is zero, because the content is not included in the HTTP::Response object. Has somebody an idea to get the content-length anyway?
Here is my code.
package LWP::UserAgent::Trace; use Time::HiRes; use Data::Dumper; use base qw/LWP::UserAgent/; sub send_request { my($self, $request, $arg, $size) = @_; my $t0 = [Time::HiRes::gettimeofday]; my $response = $self->SUPER::send_request($request,$arg,$size); my $elapsed = Time::HiRes::tv_interval($t0); my $content_length = length($response->content); my $header_length = length($response->headers_as_string); print STDERR sprintf "%s %f %d %d %d\n", $request->uri, $elapsed, $content_length, $header_length, $content_length+$header_length; return $response; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP::UserAgent hacking
by Thelonius (Priest) on Mar 04, 2006 at 19:57 UTC | |
|
Re: LWP::UserAgent hacking
by Thelonius (Priest) on Mar 04, 2006 at 17:10 UTC |