#!/usr/bin/perl -w

# very simple http1.1 client
# requests several documents, retrieves them at once
# showing one page at a time would require either parsing reply 
# headers for Content-Lenght, or using select to keep receiving and reading
# input concurrently

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);

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;

}

# receive all requests

while ( <$remote> ) {
	print;
}

close $remote;

