Re: Proxying in LWP .01 (was Re: LWP .01
Martijn Koster (m.koster@nexor.co.uk)
Tue, 18 Jul 1995 22:13:28 +0100
In message <199507182037.QAA26889@beach.w3.org>, Roy Fielding writes:
> It would be nice if there were a single function provided to load
> all the proxy_* environment variables (I'll do one for my resolution
> table eventually).
I guess you mean *_proxy?
See appended patch. The $ua->envProxy(); patch to bin/get is left as
an exercise for the reader.
I'd still like finer control on a URL level in a config file.
-- Martijn
__________
Internet: m.koster@nexor.co.uk
X-400: C=GB; A= ; P=Nexor; O=Nexor; S=koster; I=M
WWW: http://web.nexor.co.uk/mak/mak.html
*** ../lwp-0.01.orig/LWP/UserAgent.pm Mon Jul 17 11:17:37 1995
--- LWP/UserAgent.pm Tue Jul 18 22:09:53 1995
***************
*** 126,131 ****
--- 126,132 ----
'useEval' => 1,
'useAlarm' => 1,
'maxRedirect' => 5,
+ 'noProxy' => [],
}, $class;
}
}
***************
*** 216,227 ****
if ($self->useEval) {
# we eval, and turn dies into responses below
eval {
! $response = $protocol->request($request, $proturl,
$arg, $size, $timeout);
};
} else {
# user has to handle any dies, usually timeouts
! $response = $protocol->request($request, $proturl,
$arg, $size, $timeout);
}
alarm(0) if ($self->useAlarm); # no more timeout
--- 217,228 ----
if ($self->useEval) {
# we eval, and turn dies into responses below
eval {
! $response = $protocol->request($request, $proxy,
$arg, $size, $timeout);
};
} else {
# user has to handle any dies, usually timeouts
! $response = $protocol->request($request, $proxy,
$arg, $size, $timeout);
}
alarm(0) if ($self->useAlarm); # no more timeout
***************
*** 495,501 ****
--- 496,543 ----
return undef;
}
+ =head2 envProxy()
+ $ua->envProxy();
+
+ Load proxy settings from *_proxy environment variables.
+
+ =cut
+
+ sub envProxy {
+ my ($self) = @_;
+ while(($k, $v) = each %ENV) {
+ $k = lc($k);
+ next unless $k =~ /^(.*)_proxy$/;
+ if ($1 eq 'no') {
+ $self->noProxy(split(/\s*,\s*/, $v));
+ }
+ else {
+ $self->proxy($1, $v);
+ }
+ }
+ }
+
+ =head2 noProxy($domain)
+
+ $ua->noProxy('localhost', ...);
+
+ Don't proxy requests to the given domains.
+ Calling noProxy without domains clears the
+ list of domains.
+
+ =cut
+
+ sub noProxy {
+ my($self, @no) = @_;
+ if (@no) {
+ push(@{ $self->{'noProxy'} }, @no);
+ }
+ else {
+ $self->{'noProxy'} = [];
+ }
+ }
+
#####################################################################
#
# P R I V A T E S E C T I O N
***************
*** 513,521 ****
LWP::Debug::trace("($url)");
# Currently configured per scheme.
- # XXX Need to support exclusion domains for
- # first public release.
# Eventually want finer granularity
my $scheme = $url->scheme;
--- 555,574 ----
LWP::Debug::trace("($url)");
+ # check the list of noproxies
+
+ if (@{ $self->{'noProxy'} }) {
+ my $host = $url->host;
+ my $domain;
+ for $domain (@{ $self->{'noProxy'} }) {
+ if ($host =~ /$domain$/) {
+ LWP::Debug::trace("noProxy configured");
+ return undef;
+ }
+ }
+ }
+
# Currently configured per scheme.
# Eventually want finer granularity
my $scheme = $url->scheme;