Subject: | uri style proxy env vars fail to set the proxy and port correctly |
ENV{http_proxy} = http://my.proxy.domain.com:8080 results in http status
302 errors, e.g. in perlbrew.
The following test shows the problem:
t/proxy.t:
use Test::More;
use HTTP::Lite;
my $ua = HTTP::Lite->new;
{
$ua->proxy('http://my.proxy.domain.com:8080');
is($ua->{proxy}, 'my.proxy.domain.com', 'url proxy host ok');
is($ua->{proxyport}, '8080', 'url proxy port ok');
}
{
$ua->proxy('my.proxy.domain.com:8080');
is($ua->{proxy}, 'my.proxy.domain.com', 'host:port proxy host ok');
is($ua->{proxyport}, '8080', 'host:port proxy port ok');
}
{
$ua->proxy('my.proxy.domain.com');
is($ua->{proxy}, 'my.proxy.domain.com', 'host proxy host ok');
is($ua->{proxyport}, '80', 'host proxy port ok');
}
done_testing;
This svn diff fixes the problem:
--- lib/HTTP/Lite.pm (Revision 13029)
+++ lib/HTTP/Lite.pm (working copy)
@@ -511,16 +511,20 @@
{
my $self = shift;
my ($value) = @_;
+ my $scheme_re = '[a-zA-Z][a-zA-Z0-9.+\-]*'; # stolen from URI 1.55
+ my ($host, $port);
+
# Parse URL
- my ($protocol,$host,$junk,$port,$object) =
- $value =~ m{^(\S+)://([^/:]*)(:(\d+))?(/.*)$};
- if (!$host)
- {
- ($host,$port) = $value =~ /^([^:]+):(.*)$/;
+ if ($value =~ m/^$scheme_re:\/\/ (\S+) : (\d+)$/xms) {
+ $host = $1;
+ $port = $2;
}
+ else {
+ ($host,$port) = split(/:/, $value, 2);
+ }
- $self->{'proxy'} = $host || $value;
+ $self->{'proxy'} = $host;
$self->{'proxyport'} = $port || 80;
}