Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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 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
Node Status?
node history
Node Type: note [id://246723]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-07-21 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (445 votes). Check out past polls.

    Notices?