Commit 66f8201b authored by David Golden's avatar David Golden

Let explit proxy undef bypass proxies from environment

Fixes #43
parent 96c06226
......@@ -10,6 +10,9 @@ Release notes for HTTP-Tiny
- optimized URL splitting
- Passing 'undef' for any proxy attribute will prevent HTTP::Tiny from
setting the proxy from the environment.
0.043 2014-02-20 20:40:23-05:00 America/New_York
[FIXED]
......
......@@ -44,6 +44,9 @@ This constructor returns a new HTTP::Tiny object. Valid attributes include:
* C<SSL_options> —
A hashref of C<SSL_*> — options to pass through to L<IO::Socket::SSL>
Passing an explicit C<undef> for C<proxy>, C<http_proxy> or C<https_proxy> will
prevent getting the corresponding proxies from the environment.
Exceptions from C<max_size>, C<timeout> or other errors will result in a
pseudo-HTTP status code of 599 and a reason of "Internal Exception". The
content field in the response will contain the text of the exception.
......@@ -120,36 +123,45 @@ sub new {
sub _set_proxies {
my ($self) = @_;
if (! $self->{proxy} ) {
# get proxies from %ENV only if not provided; explicit undef will disable
# getting proxies from the environment
# generic proxy
if (! exists $self->{proxy} ) {
$self->{proxy} = $ENV{all_proxy} || $ENV{ALL_PROXY};
if ( defined $self->{proxy} ) {
$self->_split_proxy( 'generic proxy' => $self->{proxy} ); # validate
}
else {
delete $self->{proxy};
}
}
if (! $self->{http_proxy} ) {
if ( defined $self->{proxy} ) {
$self->_split_proxy( 'generic proxy' => $self->{proxy} ); # validate
}
else {
delete $self->{proxy};
}
# http proxy
if (! exists $self->{http_proxy} ) {
$self->{http_proxy} = $ENV{http_proxy} || $self->{proxy};
if ( defined $self->{http_proxy} ) {
$self->_split_proxy( http_proxy => $self->{http_proxy} ); # validate
$self->{_has_proxy}{http} = 1;
}
else {
delete $self->{http_proxy};
}
}
if (! $self->{https_proxy} ) {
if ( defined $self->{http_proxy} ) {
$self->_split_proxy( http_proxy => $self->{http_proxy} ); # validate
$self->{_has_proxy}{http} = 1;
}
else {
delete $self->{http_proxy};
}
# https proxy
if (! exists $self->{https_proxy} ) {
$self->{https_proxy} = $ENV{https_proxy} || $ENV{HTTPS_PROXY} || $self->{proxy};
if ( $self->{https_proxy} ) {
$self->_split_proxy( https_proxy => $self->{https_proxy} ); # validate
$self->{_has_proxy}{https} = 1;
}
else {
delete $self->{https_proxy};
}
}
if ( $self->{https_proxy} ) {
$self->_split_proxy( https_proxy => $self->{https_proxy} ); # validate
$self->{_has_proxy}{https} = 1;
}
else {
delete $self->{https_proxy};
}
# Split no_proxy to array reference if not provided as such
......
......@@ -31,5 +31,19 @@ for my $proxy ("http://localhost:8080/", "http://localhost:8080"){
like($@, qr{http_proxy URL must be in format http\[s\]://\[auth\@\]<host>:<port>/});
}
# Explicitly disable proxy
{
local $ENV{all_proxy} = "http://localhost:8080";
local $ENV{http_proxy} = "http://localhost:8080";
local $ENV{https_proxy} = "http://localhost:8080";
my $c = HTTP::Tiny->new(
proxy => undef,
http_proxy => undef,
https_proxy => undef,
);
ok(!defined $c->proxy, "proxy => undef disables ENV proxy");
ok(!defined $c->http_proxy, "http_proxy => undef disables ENV proxy");
ok(!defined $c->https_proxy, "https_proxy => undef disables ENV proxy");
}
done_testing();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment