edan has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
I have a script that makes an HTTP request directly by opening a socket and reading the response (I can't use LWP::UserAgent because the program is multi-tasking, so it can't block while waiting for the response). Okay, so now that I have the HTTP response in a buffer, I want to know what I've got there. Is there an easy way to turn it into an HTTP::Response object, so I can query some info out of it? I didn't see an appropriate method in the perldoc...
In fact, all I really need is the response code. So, if no one has a good idea of how to turn it into an HTTP::Response, perhaps you can have a look at this snippet and see if it looks okay as far as parsing the response for the code:
# $buf has the reponse read directly off the socket # the first line should be the status line my $response_ok = $buf =~ /^(HTTP[^\r\n]+)\r?\n/i; my $status_line = $1; if (not $response_ok) { # yikes, response has no status line!? (bail out) } my ($protocol, $status, $msg) = split ' ', $status_line; if ($status == 200) { # success, got 200 (OK) response } else { # error, not OK response }
TIA,
--3dan
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: create a HTTP::Response object from a raw buffer?
by rob_au (Abbot) on Mar 30, 2003 at 11:38 UTC | |
Re: create a HTTP::Response object from a raw buffer?
by tachyon (Chancellor) on Mar 30, 2003 at 12:02 UTC | |
Re: create a HTTP::Response object from a raw buffer?
by BrowserUk (Patriarch) on Mar 30, 2003 at 11:47 UTC | |
Re: create a HTTP::Response object from a raw buffer?
by pg (Canon) on Mar 30, 2003 at 18:13 UTC | |
Re: create a HTTP::Response object from a raw buffer?
by jdporter (Paladin) on Mar 31, 2003 at 15:06 UTC |