-# Loads the given URL, returns: $http, $head, $body.
-#
-sub get_url_1 {
- my ($url, $referer) = @_;
-
- if (! ($url =~ m@^http://@i)) {
- error ("not an HTTP URL: $url");
- }
-
- my ($url_proto, $dummy, $serverstring, $path) = split(/\//, $url, 4);
- $path = "" unless $path;
-
- my ($them,$port) = split(/:/, $serverstring);
- $port = 80 unless $port;
-
- my $them2 = $them;
- my $port2 = $port;
- if ($http_proxy) {
- $serverstring = $http_proxy if $http_proxy;
- $serverstring =~ s@^[a-z]+://@@;
- ($them2,$port2) = split(/:/, $serverstring);
- $port2 = 80 unless $port2;
- }
-
- my ($remote, $iaddr, $paddr, $proto, $line);
- $remote = $them2;
- if ($port2 =~ /\D/) { $port2 = getservbyname($port2, 'tcp') }
- if (!$port2) {
- error ("unrecognised port in $url");
- }
-
- $iaddr = inet_aton($remote);
- error ("host not found: $remote") unless ($iaddr);
-
- $paddr = sockaddr_in($port2, $iaddr);
-
-
- my $head = "";
- my $body = "";
-
- $proto = getprotobyname('tcp');
- if (!socket(S, PF_INET, SOCK_STREAM, $proto)) {
- error ("socket: $!");
- }
- if (!connect(S, $paddr)) {
- error ("connect($serverstring): $!");
- }
-
- select(S); $| = 1; select(STDOUT);
-
- my $user_agent = "$progname/$version";
-
- my $hdrs = ("GET " . ($http_proxy ? $url : "/$path") . " HTTP/1.0\r\n" .
- "Host: $them\r\n" .
- "User-Agent: $user_agent\r\n");
- if ($referer) {
- $hdrs .= "Referer: $referer\r\n";
- }
- $hdrs .= "\r\n";
-
- if ($verbose > 3) {
- foreach (split('\r?\n', $hdrs)) {
- print STDERR " ==> $_\n";