From 4797c4ec63b172e35ca6f9bb85c2a87ac5b9334c Mon Sep 17 00:00:00 2001 From: short <> Date: Mon, 17 Jun 2002 02:07:16 +0000 Subject: [PATCH] Simple clear-operations HTTP/1.0 GET/HEAD dumper --- bin/httpgetdumb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 bin/httpgetdumb diff --git a/bin/httpgetdumb b/bin/httpgetdumb new file mode 100755 index 0000000..9aafa31 --- /dev/null +++ b/bin/httpgetdumb @@ -0,0 +1,50 @@ +#! /usr/bin/perl +# +# $Id$ + +use strict; +use warnings; + +use Socket; +use IO::Handle; +use Getopt::Std; + +use constant DEFAULT_PORT=>80; +use constant BUFFER_LENGTH=>0x1000; + +my %opts; +getopts "hH",\%opts or die "getopts()"; +@ARGV==1 && $ARGV[0]=~m#^http://([^/]+)(:\d+)?(/.*)$# + or die "Syntax: $0 [-hH] http://hostname/pathname"; +my($host,$port,$path)=($1,$2,$3); +defined $port or $port=DEFAULT_PORT; + +my $proto=getprotobyname "tcp" or die "getprotobyname \"tcp\": $!"; +socket SOCK,PF_INET,SOCK_STREAM,$proto or die "socket PF_INET,SOCK_STREAM,\"tcp\": $!"; +my $hostaddr=gethostbyname $host or die "hostname \"$host\": $!"; +my $sockaddr=sockaddr_in $port,$hostaddr or die "sockaddr_in(".inet_ntoa($hostaddr).":$port): $!"; +connect SOCK,$sockaddr or die "connect \"$host\"(".inet_ntoa($hostaddr).":$port): $!"; + +print SOCK ($opts{"h"} ? "HEAD" : "GET")." $path HTTP/1.0\r\nHost: $host\r\n\r\n"; +if ($opts{"H"}) { + while () { + chomp; + last if /^$/; + print SOCK "$_\r\n"; + } + } +SOCK->flush(); +while () { + print STDERR; + chomp; + last if /^\r?$/; + } +for (;;) { + my $buf; + my $got=read SOCK,$buf,BUFFER_LENGTH; + defined $got or die "read: $!"; + last if !$got; + die "read()=$got (<0)" if $got<0; + print $buf; + } +exit 0; -- 1.8.3.1