Subject: | IPv6 Address URLs Broken |
Date: | Wed, 7 Mar 2012 16:36:45 -0800 |
To: | "bug-Net-HTTP [...] rt.cpan.org" <bug-Net-HTTP [...] rt.cpan.org> |
From: | Nick Lamkins <Nick_Lamkins [...] symantec.com> |
Net::HTTP doesn't appear to handle ipv6 addresses correctly.
In http_configure of Net/HTTP/Methods.pm, the code will search for something that appears to be a port at the end of PeerAddr (or PeerHost). When using an ipv6 style address, this pattern may incorrectly match the last segment of an ipv6 address.
sub http_configure {
my($self, $cnf) = @_;
die "Listen option not allowed" if $cnf->{Listen};
my $explict_host = (exists $cnf->{Host});
my $host = delete $cnf->{Host};
my $peer = $cnf->{PeerAddr} || $cnf->{PeerHost};
if (!$peer) {
die "No Host option provided" unless $host;
$cnf->{PeerAddr} = $peer = $host;
}
if ($peer =~ s,:(\d+)$,,) { # <-- BUG HERE - $peer could be an ipv6 address
$cnf->{PeerPort} = int($1); # always override
}
<snip>
Sample Code using LWP::UserAgent
#!/usr/bin/env perl
use Net::INET6Glue::INET_is_INET6;
use LWP::UserAgent;
my $url = 'http://[1234:1234:1234:5:abc:abcd:abc1:123]:80/foo/bar.pl?param=true';
my $user_agent = LWP::UserAgent->new;
my $request = HTTP::Request->new(GET => $url);
my $response = $user_agent->request($request);
if ($response->is_success) {
print "OK\n";
} else {
die($response->status_line);
}
The error is shown as:
500 Can't connect to 1234:1234:1234:5:abc:abcd:abc1:123:80 (Connection refused) at ./bug.pl line 16.
Setting EXTRA_SOCK_OPTS turns out to be an awful workaround.
@LWP::Protocol::http::EXTRA_SOCK_OPTS = (PeerAddr => '1234:1234:1234:5:abc:abcd:abc1:123:80');
Nick Lamkins
Sr. Software Engineer, Symantec Corporation
www.symantec.com<http://www.symantec.com/>
Show quoted text
________________________________
Office: (503) 614-5039 Fax: (503) 614-5060
nick_lamkins@symantec.com
________________________________
[cid:9CC5DD25-B7F1-488B-8109-2C9197866A89]
This message (including any attachments) is intended only for the use of the individual or entity to which it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law or may constitute as attorney work product. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, notify us immediately by telephone and (i) destroy this message if a facsimile or (ii) delete this message immediately if this is an electronic communication.