Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

by tachyon (Chancellor)
on Mar 30, 2003 at 12:02 UTC ( #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 use IO::Socket::INET; $get = ''; $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 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:\>




Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-11-14 01:23 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (161 votes). Check out past polls.