libwww-perl / LWP-Protocol-https

Provide https support for LWP::UserAgent
https://metacpan.org/pod/LWP::Protocol::https
Other
16 stars 35 forks source link

LWP fails to try connect with IPv4 when IPv6 on remote not reachable #79

Closed GwenDragon closed 3 weeks ago

GwenDragon commented 3 weeks ago

If fetching content with lwp-request or GET (the perl script) and the remote server has IPv6 and IPv4, but IPv6 is not reachable, lwp-request dies with error message "500 Can't connect to gwendragon.de:443 (Bad address)" Expected is like wget or curl that LWP connect is tried on IPv6 and IPv4. The Socket error message does not really point to the issue and makes it hard to use lwp-request as command line tool.

I checked the problem with a own program.

test case

use strict; 
use warnings; 
use 5.020;

use LWP::UserAgent ();
use Data::Dumper;

my $ua = LWP::UserAgent->new(timeout => 3);
$ua->ssl_opts( 
        SSL_ca_file => 'X:\etc\ssl\certs\cacert.pem',
        verify_hostname => 1,
);
$ua->agent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36');

my $response = $ua->get('https://gwendragon.de');

if ($response->is_success) {
    print $response->decoded_content;
}
else {
    say $response->status_line;
    #say Dumper $response;
}

With use IO::Socket::SSL qw/debug3/; output gives: DEBUG: .../IO/Socket/SSL.pm:3020: new ctx 2719281884640 DEBUG: .../IO/Socket/SSL.pm:705: socket not yet connected DEBUG: .../IO/Socket/SSL.pm:705: socket not yet connected DEBUG: .../lib/Net/HTTPS.pm:67: local error: IO::Socket::IP configuration failed DEBUG: .../IO/Socket/SSL.pm:3069: free ctx 2719281884640 open=2719281884640 DEBUG: .../IO/Socket/SSL.pm:3073: free ctx 2719281884640 callback DEBUG: .../IO/Socket/SSL.pm:3080: OK free ctx 2719281884640 500 Can't connect to gwendragon.de:443 (Bad address)

Environment

Windows 11 23H2 StrawberryPerl 5.36.3.1 x64 libwww-perl-6.77 LWP-Protocol-https-6.14 Net-SSLeay-1.94 Net-SSLGlue-1.058 Crypt-SSLeay-0.72

oalders commented 3 weeks ago

I can't easily replicate this. Does the information on fallbacks here point to a reasonable solution? https://metacpan.org/pod/IO::Socket::SSL#Description-Of-Methods

GwenDragon commented 3 weeks ago

Let us wait what Steffen says about the issue.

GwenDragon commented 3 weeks ago

Seems to be unfixable as IO::Socket has no fallback.