#!/usr/bin/env perl print <; $req = ''; ($method, $url, $proto) = split; $no_host_needed = 0; if ($proto) { while () { print STDOUT "got: $_\n"; next if (/^Connection:/i); /^Content-Length: (\S*)/i && ($content_length=$1); /^Host: / && ($no_host_needed = 1); $req .= $_; last if ($_ eq "\015\012" || $_ eq "\012"); } } else { $proto = "HTTP/0.9"; } print STDOUT "request for $method $url $proto\n"; if ($content_length) { read(NS, $k, $content_length); $req .= $k; $k = ''; } if ($url !~ m#^http://#) { print STDOUT "attempt to access as server: $url\n"; &error("This functionality is coming SOON.\n"); goto DIE; } ($url =~ m#^(http)://([^:/]+):(\d+)/(.*)$#i) && (($uproto, $them, $port, $page) = ($1, $2, $3, "/$4")); ($url =~ m#^(http)://([^:/]+):(\d+)$#i) && (($uproto, $them, $port, $page) = ($1, $2, $3, '/')); ($url =~ m#^(http)://([^:/]+)/(.*)$#i) && (($uproto, $them, $port, $page) = ($1, $2, 80, "/$3")); ($url =~ m#^(http)://([^:/]+)$#i) && (($uproto, $them, $port, $page) = ($1, $2, 80, '/')); shutdown(NS, 0); print STDOUT "attempting connection\n"; ($name, $aliases, $type, $len, $thataddr) = gethostbyname($them); if (!$thataddr) { print STDOUT "no such host: $them\n"; &error("No hostname found for host $them.\n"); goto DIE; } $that = pack($sockaddr, 2, $port, $thataddr, 0); socket(T, 2, 1, 6) || print STDOUT "hmm!: $!\n"; setsockopt(T, 65535, 4101, pack("LL", 15, 0)) || print STDOUT ("can't set socket timeout: this socket may hang\n"); setsockopt(T, 65535, 4102, pack("LL", 15, 0)) || print STDOUT ("can't set socket timeout: this socket may hang\n"); eval 'alarm 15; connect(T, $that) || die($!);'; alarm 0; if ($@) { print STDOUT "connection failed: $@\n"; &error("Could not connect to host $them.\n"); goto DIE; } select(T); $|++; print STDOUT "connected to $them\n"; $x = "$method $page HTTP/1.0\015\012" . "X-Proxy: Copperweb\015\012" . "Connection: close\015\012" . (($no_host_needed) ? '' : "Host: $them\015\012") . "$req"; print STDOUT $x; print T $x; $content_type = ''; $content_length = 0; $req = ''; $nclreq = ''; HEADS: while() { if (/^Content-type: (\S+)/i) { $content_type = $1; $content_type =~ s/;.+$//; $req .= "Content-type: $content_type\015\012"; $nclreq .= "Content-type: $content_type\015\012"; next HEADS; } if (/^Content-length: (\S+)/i) { $req .= $_; next HEADS; } $req .= $_; $nclreq .= $_; last if ($_ eq "\015\012" || $_ eq "\012"); } $nbuf = ''; $gbuf = ''; if (&lca($content_type) ne "text/html") { print STDOUT $req; print NS $req; print STDOUT "not translating content type $content_type\n"; while() { &transmit($_); } } else { print STDOUT $nclreq; print NS $nclreq; print STDOUT "translating content type $content_type\n"; $/ = ">"; $stop = 0; $bytes = 0; while() { $bytes += length; print STDOUT "read $bytes bytes\n"; if (!$stop && !/') { if (substr($buf, 0, 4) eq "