Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: create a HTTP::Response object from a raw buffer?

by tachyon (Chancellor)
on Mar 30, 2003 at 12:02 UTC ( [id://246723]=note: print w/replies, xml ) Need Help??


in reply to create a HTTP::Response object from a raw buffer?

If you just want the codes (as you say) just read the header....If you want an HTTP::Response Object just create one by splitting the return into header and content. Parse the header ( All in form Key: Value\n - should unwrap soft line breaks first with s/\n^\s+//gm first ) then build your HTTP::Response object out of the parsed header and content. Note HTTP::Response is a subclass of HTTP::Message which also uses HTTP::Headers so you will have to read the (brief) docs for all of these. Data::Dumper will show you the Response object which is just a hash of hashes structure.

C:\>type test.pl use IO::Socket::INET; $get = 'www.perl.org'; $sock = IO::Socket::INET->new(PeerAddr => $get, PeerPort => 'http(80)', Proto => 'tcp'); print $sock "GET http://$get HTTP/1.0\015\012\015\012"; read( $sock, $chopped_header , 100); close $sock; my ( $rc, $msg ) = $chopped_header =~ m/HTTP[^\s]+\s+(\d+)\s+([^\n]+)/ +; print "$chopped_header.....[blah]\n\n"; print "RC=$rc and MSG=$msg\n"; C:\>perl test.pl HTTP/1.0 200 OK Date: Sun, 30 Mar 2003 11:59:58 GMT Server: Apache/2.0.44-dev (Unix) DAV/2 Accept.....[blah] RC=200 and MSG=OK C:\>

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246723]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (None)
    As of 2024-04-25 04:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found