evdb / HTTP-Async

process multiple HTTP requests in parallel without blocking
http://search.cpan.org/dist/HTTP-Async/lib/HTTP/Async.pm
8 stars 14 forks source link

ssl_options passed into add_with_opts are not honoured #18

Open trevor-indosoft opened 7 years ago

trevor-indosoft commented 7 years ago

In troubleshooting some issue with multiple https request with SSL_verifycn_scheme set to http, I noticed that only the global ssl_optionswere actually being passed into the Net::HTTPS::NB constructor.

The simply solution was to add the options stored in $args{ssl_opts} back into %args after the global ssl_options are added.

    # Add SSL options, if any, to args
    my $ssl_options = $self->_get_opt('ssl_options');
    @args{ keys %$ssl_options } = values %$ssl_options if $ssl_options;

    # Override global SSL options with request-specific ones, if any
    @args{ keys %{$args{ssl_opts}} } = values %{$args{ssl_opts}} if $args{ssl_opts};

This has allowed me to successfully make requests to multiple sites using hostname verification. Sample:

#!/usr/bin/perl

use HTTP::Async;
use HTTP::Request::Common;
$IO::Socket::SSL::DEBUG = 3;

my $async = HTTP::Async->new(ssl_options => {SSL_verifycn_scheme => 'http'});
$async->add_with_opts(GET('https://site1.example.com'), {ssl_options => {SSL_hostname => 'site1.example.com'}});
$async->add_with_opts(GET('https://site2.example.com'), {ssl_options => {SSL_hostname => 'site2.example.com'}});

while (my $response = $async->wait_for_next_response) {
    print STDOUT $response->request->url . "\n";
    print STDOUT $response->content . "\n";
    print STDOUT $response->code . "\n";
    print STDOUT $response->message . "\n\n";
}