Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to create a HTTP::Response object from a raw buffer? by edan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found