#!/usr/bin/perl -w

# very simple http1.1 client
# forks another process to dump output

use IO::Socket;
unless (@ARGV > 0) { die "usage: $0 host " }
$host = shift(@ARGV);

$EOL = "\015\012";

# socket & connect
$remote = IO::Socket::INET->new( Proto     => "tcp",
								 PeerAddr  => $host,
								 PeerPort  => "http(80)",
							   );
unless ($remote) { die "cannot connect to http daemon on $host" }
$remote->autoflush(1);

$childpid = fork();

if ($childpid) {
	# parent

	print "Enter document names, empty line to quit\n";

	# send all requests 
	while(<>) {
		chop;
		last if length($_) < 2;
		($document) = split;

		print $remote "GET /$document HTTP/1.1" . $EOL . "Host: " . $host . $EOL x 2;

	}

} else {
	# child

	# receive all requests

	while ( <$remote> ) {
		print;
	}
}

close $remote;

