Skip to content

Commit

Permalink
Make detection of IPv4 vs. IPv6 more resilient
Browse files Browse the repository at this point in the history
This comes from

libwww-perl/WWW-Mechanize#280

Thanks to Shoichi Kaji for the code and Olaf Alders for the review
  • Loading branch information
Max Maischein committed Sep 10, 2019
1 parent 5603dff commit b7cf696
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ my %module = (
'Cwd' => 0,
'File::Basename' => 0,
'HTTP::Response' => 0,
'HTTP::Daemon' => 0,
'HTTP::Daemon' => 6.05,
'IO::Socket::INET' => 0, # For port probing
'CGI' => 0,
'HTTP::Request::AsCGI' => 0,
'LWP::Simple' => 0, # just for testing
'Socket' => 0, # for detecting 127.0.0.1 vs [::1]
'URI' => 0,
'URI::URL' => 0,
},
TEST_REQUIRES => {
Expand Down
23 changes: 13 additions & 10 deletions lib/Test/HTTP/log-server
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Thanks to merlyn for nudging me and giving me this snippet!
use strict;
use HTTP::Daemon;
use HTTP::Daemon 6.05;
use URI;
use CGI;
use HTTP::Request::AsCGI;
use Getopt::Long;
use Socket();
our $VERSION = '0.63';

$|++;
Expand All @@ -13,16 +15,17 @@ GetOptions(
'f=s' => \my $url_filename,
);

#my $host = 'localhost';
my $host = '127.0.0.1';
my $d = HTTP::Daemon->new(
LocalAddr => $host,
) or die;
my $d = HTTP::Daemon->new or die;

my $url = URI->new( $d->url );
if( $d->sockdomain == Socket::AF_INET ) {
$url->host('127.0.0.1');
} elsif ($d->sockdomain == Socket::AF_INET6 ) {
$url->host('[::1]');
} else {
die "Unexpected sockdomain: " . $d->sockdomain;
};

# HTTP::Deamon doesn't return http://localhost:.../
# for LocalAddr => 'localhost'. This causes the
# tests to fail of many machines.
( my $url = URI->new($d->url) )->host($host);
{
my $fh;
if( $url_filename ) {
Expand Down

0 comments on commit b7cf696

Please sign in to comment.