Skip to content

IPv6 Address URLs Broken [rt.cpan.org #75618] #42

@oalders

Description

@oalders

Migrated from rt.cpan.org#75618 (status was 'open')

Requestors:

Attachments:

From [email protected] on 2012-03-08 00:37:02:

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/>
________________________________
Office: (503) 614-5039  Fax: (503) 614-5060
[email protected]
________________________________

[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.

From [email protected] on 2013-01-24 01:07:46:

I have the same problem. The workaround seems very clumsy. Is there any
intention to fix this?

Could this just be skipped for IPv6 addresses?

From [email protected] on 2013-04-10 14:51:35:

I've spent some time over past few days trying to figure out exactly same
issue as is described here. I wish I've had find this bug report sooner.

Anyway, I've reached the same conclusion as Nick. That code should be
skipped for IPv6 or better regexp should be in place to correctly extract
port from all addresses.

What I've found to be easier workaround than setting EXTRA_SOCK_OPTS is to
use double square brackets. I've used same example code above just added some 
debugging output to Net::HTTP::Methods

my $url = 'http://[fc00::3]/';
$VAR1 = {
          'Proto' => 'tcp',
          'PeerAddr' => 'fc00::3',
          'SendTE' => 1,
          'PeerPort' => 3,               # PeerPort incorrectly set to 3
          'KeepAlive' => ''
        };

my $url = 'http://[[fc00::3]]/';
$VAR1 = {
          'Proto' => 'tcp',
          'PeerAddr' => '[fc00::3]',
          'SendTE' => 1,
          'PeerPort' => 80,              # PeerPort is now correctly set to default
          'KeepAlive' => ''
        };

From [email protected] on 2014-07-22 21:40:03:

I humbly offer:

https://github.com/libwww-perl/net-http/pull/10
https://github.com/libwww-perl/libwww-perl/pull/58

The combination will use IO::Socket::IP or IO::Socket::INET6 (if found); and uses URI to do host address parsing (in order to correctly parse [2001:db8::1]:80).

From [email protected] on 2014-07-25 22:43:24:

My patches appear to be accepted, and a new release produced.

Please consider updating to these packages:

Net::HTTP (6.07)
LWP (6.080
URI (1.64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions