I have a need to collet timings on individual HTTP(s)
requests -- specifically, I'd like to caputure the
elapsed time from when the request is sent until:
(a) the first byte (or packet or chunk?) of the
response is received, and
(b) until the entire response is received
I've been doing something close, like this:
$start_time = [gettimeofday];
$response = $ua->request( $req,
sub {
my($chunk, $res) = @_;
unless (defined $first_byte_secs) {
$first_byte_secs = tv_interval($start_time);
}
$content = $content . $chunk;
}
);
$last_byte_secs = tv_interval($start_time);
This works okay, except when I run into redirects, and
the system I'm testing has several of them in key
spots. While the overall time is still correct, the
split between [first byte received] & [last byte
received] is thrown off significantly. This is
important because I'm using the difference to calcuate
network transfer time.
I think what I need to do is make use of the chaining
of $request->previous() & extend HTTP::Response to
include fields for these two times. I can then walk the
chain of previous() responses & total up the "server
times" & the "transfer times".
However, I'm at a loss as to how to best accomplish
this. Any suggestions?
In the course of doing this, I have also created a
subclass of UserAgent that "properly" handles redirects
of POST requests. (By properly, I mean it issues a GET
rather than a POST on the redirected URL.) If anyone is
interested, I will post it. (pun intended)
Thanks,
David
[EMAIL PROTECTED]