Skip to content

Commit

Permalink
Item14545: Implement NoProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Dec 1, 2017
1 parent b778ff1 commit 215bcec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/lib/Foswiki.spec
Expand Up @@ -1084,6 +1084,10 @@ $Foswiki::cfg{AccessibleHeaders} = ['Accept-Language', 'User-Agent'];
# http://username:password@proxy.your.company:8080. # http://username:password@proxy.your.company:8080.
$Foswiki::cfg{PROXY}{HOST} = undef; $Foswiki::cfg{PROXY}{HOST} = undef;


# **STRING 50 LABEL="No Proxy" CHECK="undefok emptyok"**
# List of domains that are accessed directly instead of going by the proxy.
$Foswiki::cfg{PROXY}{NoProxy} = '';

# **BOOLEAN LABEL="Client IP" ** # **BOOLEAN LABEL="Client IP" **
# Foswiki normally uses the REMOTE_ADDRESS as the client IP. If Foswiki is behind # Foswiki normally uses the REMOTE_ADDRESS as the client IP. If Foswiki is behind
# a proxy, Foswiki will see the proxy's address as the Client IP. Enable this switch if you # a proxy, Foswiki will see the proxy's address as the Client IP. Enable this switch if you
Expand Down
6 changes: 6 additions & 0 deletions core/lib/Foswiki/Net.pm
Expand Up @@ -116,6 +116,11 @@ sub getExternalResource {
my $uri = URI::URL->new($url); my $uri = URI::URL->new($url);
my $proxyHost = $this->{PROXYHOST} || $Foswiki::cfg{PROXY}{HOST}; my $proxyHost = $this->{PROXYHOST} || $Foswiki::cfg{PROXY}{HOST};
my $puri = $proxyHost ? URI::URL->new($proxyHost) : undef; my $puri = $proxyHost ? URI::URL->new($proxyHost) : undef;
my @noProxy =
( $puri && $Foswiki::cfg{PROXY}{NoProxy} )
? split( /\s*,\s*/, $Foswiki::cfg{PROXY}{NoProxy} )
: undef;

my $request; my $request;


require HTTP::Request; require HTTP::Request;
Expand All @@ -138,6 +143,7 @@ sub getExternalResource {
if ( $uri->can("userinfo") && defined $uri->userinfo() ); if ( $uri->can("userinfo") && defined $uri->userinfo() );
my $ua = new Foswiki::Net::UserCredAgent( $user, $pass ); my $ua = new Foswiki::Net::UserCredAgent( $user, $pass );
$ua->proxy( [ 'http', 'https' ], $puri->as_string() ) if $puri; $ua->proxy( [ 'http', 'https' ], $puri->as_string() ) if $puri;
$ua->no_proxy(@noProxy) if @noProxy;
my $response = $ua->request($request); my $response = $ua->request($request);
return $response; return $response;
} }
Expand Down

0 comments on commit 215bcec

Please sign in to comment.