X-Git-Url: https://git.jankratochvil.net/?p=nethome.git;a=blobdiff_plain;f=bin%2Fhttpgetdumb;h=3a782369f9d1e992c02b2da23dca16f18c19d8bd;hp=6ea04e043eb9e28e7c19bc30955712f6ffa458e0;hb=f1fd1da97405a124a824d3808d6bc59df1b16b9b;hpb=7e0d9d93b45e6f6847013673efae348ad2ca3bd9 diff --git a/bin/httpgetdumb b/bin/httpgetdumb index 6ea04e0..3a78236 100755 --- a/bin/httpgetdumb +++ b/bin/httpgetdumb @@ -13,10 +13,10 @@ 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+))?(/.*)$# +getopts "xhH",\%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); +my($hostport,$host,$port,$path)=($1,$2,$3,$4); defined $port or $port=DEFAULT_PORT; my $proto=getprotobyname "tcp" or die "getprotobyname \"tcp\": $!"; @@ -25,7 +25,16 @@ 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"; +print SOCK ($opts{"h"} ? "HEAD" : "GET")." $path HTTP/1.0\r\n"; +my %header=( + "Host"=>$hostport, + "X-httpgetdumb"=>'$Id$', + ); +$header{"Accept"}="application/xhtml+xml" if $opts{"x"}; +while (my($key,$val)=each(%header)) { + print SOCK "$key: $val\r\n"; + } +print SOCK "\r\n"; if ($opts{"H"}) { while () { chomp;