--- toast 2004/02/02 01:45:56 1.283 +++ toast 2004/02/02 05:24:05 1.284 @@ -233,6 +233,7 @@ "postarmprog" => superuser ? "/sbin/ldconfig" : "", "editprog" => "", "defaultcmd" => "help", + "httpproxy" => $ENV{http_proxy} || "", "quiet" => false, "autofind" => true, "autochange" => true, @@ -284,7 +285,9 @@ sub isboolopt($) { my($name) = @_; - return isopt($name) && isboolean($optdefault{$name}); + return false unless isopt($name); + my($def) = $optdefault{$name}; + return !defined($def) || $def eq true; } sub checkoptname($) @@ -745,9 +748,17 @@ $url =~ m!^http://([\w\.]+)(:(\d+))?(/[\!-\~]*)?$! || error("bad url: $url"); explain("fetching $url"); my($host, $port, $path) = ($1, $3 || 80, $4 || '/'); + my($hdrhost) = $port == 80 ? $host : "$host:$port"; + if(httpproxy) + { + $path = "http://$host:$port$path"; + httpproxy =~ m!^(http://)?([\w\.]+)(:(\d+))?([^:]+)(:(\d+))?/?$! + || error("bad httpproxy: " . httpproxy); + ($host, $port) = ($2, $4 || 8080); + } my($ip) = gethostbyname($host) || error("gethostbyname $host: $!"); my($uagent) = "$myname/$myversion ($^O; $myurl)"; - my($request) = "$method $path HTTP/1.0\r\nHost: $host\r\n". + my($request) = "$method $path HTTP/1.0\r\nHost: $hdrhost\r\n". "User-Agent: $uagent\r\nAccept: */*\r\n\r\n"; socket(HANDLE, 2, 1, 0) || error("$!"); connect(HANDLE, pack("Sna4x8", 2, $port, $ip)) || @@ -819,6 +830,7 @@ $url =~ /^(\w+):/ || error("bad url: $url"); my($proto) = lc($1); + local($ENV{http_proxy}) = httpproxy if httpproxy; $proto eq "file" && openfileurl(*HANDLE, $url) || $proto eq "ssh" && opensshurl (*HANDLE, $url) || openwgeturl(*HANDLE, $url) || @@ -5265,6 +5277,19 @@ invoking B<toast> without command-line options or arguments is always equivalent to running B<toast help>, regardless of this option's setting. Default: C<help>. + +=item B<--httpproxy=>I<URL> + +If I<URL> is non-empty, B<toast get> will use the given URL as the +proxy server for C<http> and C<https> URLs. When using B<wget> or +B<GET>, the given URL will be exported in the C<http_proxy> environment +variable without further checking if non-empty. When using built-in +HTTP, the proxy URL should be of the form C<I<hostname>:I<port>> +or C<http://I<hostname>:I<port>/>. Note that using an empty URL will +not cause C<http_proxy> to be removed from the environment of B<wget> +or B<GET>. The proxy string is not exported during B<toast build>. +Default: the current value of the C<http_proxy> environment variable, +or the empty string if that variable is not set. =item S<B<--quiet> | B<--noquiet>>