JoeJaz has asked for the wisdom of the Perl Monks concerning the following question:
This sample is simplified for this question. As I mentioned, with this code, I can easily grab the first line of the headers. However, I want to grab the rest of the headers. For example, I need to grab the "Host: somehost.com" header, which is typically the second line. Thinking that I could treat this like any other file handel, I replaced the contents of the while loop with this:#!/usr/bin/perl -w + use strict; use IO::Socket; my $socket_server = IO::Socket::INET->new( Listen => 5, LocalAddr => 'localhost', LocalPort => 7788, Reuse => 1, Proto => 'tcp' ) or die "$!"; my ($c, $request_headers); while ($c = $socket_server->accept()) { $c->autoflush(1); my $request_headers = <$c>; print $request_headers; }
However, line 3 causes the web browser to stall. I am guessing that the program doesn't know when all of the headers have been displayed and just hangs. I have tried a variety of different things to try to get the program to stop reading once the headers have been displayed, but I have had no success. I would be overjoyed if someone has any suggestions regarding this problem. Thank you for reading this, Joe$c->autoflush(1); my @request_headers = <$c>; # line 3 for $header_line (@request_headers) { print $header_line; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket Get Headers
by ikegami (Patriarch) on Oct 02, 2004 at 02:57 UTC | |
by JoeJaz (Monk) on Oct 02, 2004 at 05:02 UTC | |
by JoeJaz (Monk) on Oct 04, 2004 at 08:55 UTC | |
by ikegami (Patriarch) on Oct 04, 2004 at 14:31 UTC | |
by JoeJaz (Monk) on Oct 04, 2004 at 22:26 UTC | |
by ikegami (Patriarch) on Oct 04, 2004 at 22:34 UTC | |
|