Subject: | Test failures caused by "localhost" resolution under IPv6 |
Date: | Wed, 7 Feb 2018 23:00:54 +0000 |
To: | bug-Test-HTTP-Server-Simple [...] rt.cpan.org |
From: | Richard Leach <rich+perl [...] hyphen-dash-hyphen.info> |
Hi,
The module synopsis, as followed in modules such as HTTP::Async, causes a
listening HTTP::Server::Simple instance to be bound to the IPv4 localhost
address.
my $s = My::WebServer->new;
Test::HTTP::Server::Simple's started_ok() method returns the following
upon success:
return "http://localhost:$port";
But on a host with a dual IPv4/IPv6 stack, "localhost" is likely to resolve
to the IPv6 localhost address, meaning that any tests performed using this
URL root will fail.
A possible fix (that worked for me) would be to return from started_ok() in
this manner:
my $localhost = ( $self->family == 2 ) ? '127.0.0.1' : '::1' ;
return "http://$localhost:$port";
Thanks,
Rich