Subject: | URI confused by port numbers with no scheme? |
use URI;
my $URI = new URI->new('something.com:3128');
print $URI->scheme,"\n";
Results in output 'something.com'
Tracked this down after my cpanm as not working when attempting to use $http_proxy and $https_proxy environment variables.
I kept getting the error:
501 Protocol scheme 'myproxy.com:3128' is not supported. This is because I had http_proxy set to myproxy.com:3120, and cpanm calls LWP::UserAgent with env_proxy => 1.
At some point, LWP::UserAgent calls $uri->scheme and it returns myproxy.com instead of undef.
Snip from LWP::UserAgent send_request:
# Locate protocol to use
my $proxy = $request->{proxy};
if ($proxy) {
$scheme = $proxy->scheme;
}
unless ($protocol) {
$protocol = eval { LWP::Protocol::create($scheme, $self) };
$proxy is a URI::_foreign which is URI::_generic which overrides "no_scheme_ok" as being true. so calling $proxy->scheme returns the proxy name, then it tries to load that as a protocol resulting in the above error.
I got lost when tracking down how calling ->scheme returns the hostname.
URI version 999 required--this is only version 1.60.
LWP::UserAgent version 999 required--this is only version 6.05.
Also installed URI 1.67 via local::lib and same results (something.com returned as ->scheme).
THe workaround (at least for cpanm) is to call the (as far as I can tell) undocumented --no-lwp command line option.
Thanks,
\- Mike