Subject: | configure(proxy_host, proxy_port), SSL and fail_on_error broken |
There are patches for SSL and the proxy_host and proxy_port problem. I've rolled them up into one and included them here.
The other problem is either with on_error, or something else! ;) The module will fail and quit completely after the first encounter of a problem with a URL when using concurrent or asynchronous URLs. So, if you connected fine to google.com, and then went to blah49.com and it failed, the module won't go to the next URL in queue, it just quits. I don't know if its on_error, or something else. I also tinkered with fail_on_error, but got no results with 0 or 1.
Subject: | Net-Async-HTTP.patch |
diff -Naur Net-Async-HTTP-0.39/lib/Net/Async/HTTP/Connection.pm Net-Async-HTTP-0.39p1/lib/Net/Async/HTTP/Connection.pm
--- Net-Async-HTTP-0.39/lib/Net/Async/HTTP/Connection.pm 2015-07-13 04:41:41.000000000 -1000
+++ Net-Async-HTTP-0.39p1/lib/Net/Async/HTTP/Connection.pm 2017-01-22 07:02:48.900345147 -1000
@@ -53,7 +53,7 @@
my $self = shift;
my %params = @_;
- foreach (qw( pipeline max_in_flight ready_queue decode_content )) {
+ foreach (qw( pipeline max_in_flight ready_queue decode_content is_proxy )) {
$self->{$_} = delete $params{$_} if exists $params{$_};
}
@@ -267,7 +267,8 @@
);
} : undef;
- # Unless the request method is CONNECT, the URL is not allowed to contain
+ # Unless the request method is CONNECT, or we are connecting to a
+ # non-transparent proxy, the URL is not allowed to contain
# an authority; only path
# Take a copy of the headers since we'll be hacking them up
my $headers = $req->headers->clone;
@@ -277,8 +278,13 @@
}
else {
my $uri = $req->uri;
- $path = $uri->path_query;
- $path = "/$path" unless $path =~ m{^/};
+ if ( $self->{is_proxy} ) {
+ $path = $uri->as_string;
+ }
+ else {
+ $path = $uri->path_query;
+ $path = "/$path" unless $path =~ m{^/};
+ }
my $authority = $uri->authority;
if( defined $authority and
my ( $user, $pass, $host ) = $authority =~ m/^(.*?):(.*)@(.*)$/ ) {
diff -Naur Net-Async-HTTP-0.39/lib/Net/Async/HTTP.pm Net-Async-HTTP-0.39p1/lib/Net/Async/HTTP.pm
--- Net-Async-HTTP-0.39/lib/Net/Async/HTTP.pm 2015-07-13 04:41:41.000000000 -1000
+++ Net-Async-HTTP-0.39p1/lib/Net/Async/HTTP.pm 2017-01-22 07:02:48.900345147 -1000
@@ -412,6 +412,7 @@
ready_queue => $ready_queue,
( map { $_ => $self->{$_} }
qw( max_in_flight pipeline read_len write_len decode_content ) ),
+ is_proxy => $args{is_proxy},
on_closed => sub {
my $conn = shift;
@@ -658,6 +659,7 @@
return $self->get_connection(
host => $args{proxy_host} || $self->{proxy_host} || $host,
port => $args{proxy_port} || $self->{proxy_port} || $port,
+ is_proxy => !!($args{proxy_host} || $self->{proxy_host}),
SSL => $args{SSL},
%{ $self->{ssl_params} },
( map { m/^SSL_/ ? ( $_ => $args{$_} ) : () } keys %args ),
diff -Naur Net-Async-HTTP-0.39/t/01request.t Net-Async-HTTP-0.39p1/t/01request.t
--- Net-Async-HTTP-0.39/t/01request.t 2015-07-13 04:41:41.000000000 -1000
+++ Net-Async-HTTP-0.39p1/t/01request.t 2017-01-22 07:02:48.900345147 -1000
@@ -35,7 +35,8 @@
my $error;
my $request = $args{req};
- my $host = $args{no_host} ? $request->uri->host : "host$hostnum"; $hostnum++;
+ my $host = $args{no_host} ? $request->uri->host : $http->{proxy_host} || "host$hostnum"; $hostnum++;
+ my $service = $http->{proxy_port} || 80;
my $peersock;
no warnings 'redefine';
@@ -43,8 +44,8 @@
my $self = shift;
my %args = @_;
- $args{host} eq $host or die "Expected $args{host} eq $host";
- $args{service} eq "80" or die "Expected $args{service} eq 80";
+ $args{host} eq $host or die "Expected $args{host} eq $host";
+ $args{service} eq $service or die "Expected $args{service} eq $service";
( my $selfsock, $peersock ) = IO::Async::OS->socketpair() or die "Cannot create socket pair - $!";
$self->set_handle( $selfsock );
@@ -218,6 +219,33 @@
expect_res_content => "Hello, world!",
);
+$http->configure(proxy_host => 'proxyhost',proxy_port=>3128);
+do_test_req( "GET over proxy",
+ req => $req,
+ host => "myhost",
+
+ expect_req_firstline => "GET http://myhost/some/path HTTP/1.1",
+ expect_req_headers => {
+ Host => "myhost",
+ },
+
+ response => "HTTP/1.1 200 OK$CRLF" .
+ "Content-Length: 13$CRLF" .
+ "Content-Type: text/plain$CRLF" .
+ "Connection: Keep-Alive$CRLF" .
+ $CRLF .
+ "Hello, world!",
+
+ expect_res_code => 200,
+ expect_res_headers => {
+ 'Content-Length' => 13,
+ 'Content-Type' => "text/plain",
+ 'Connection' => "Keep-Alive",
+ },
+ expect_res_content => "Hello, world!",
+);
+$http->configure(proxy_host => undef,proxy_port=>undef);
+
$req = HTTP::Request->new( GET => "/empty", [ Host => "myhost" ] );
do_test_req( "GET with empty body",
diff -Naur Net-Async-HTTP-0.39/t/24local-connect-redir-ssl.t Net-Async-HTTP-0.39p1/t/24local-connect-redir-ssl.t
--- Net-Async-HTTP-0.39/t/24local-connect-redir-ssl.t 2015-07-13 04:41:41.000000000 -1000
+++ Net-Async-HTTP-0.39p1/t/24local-connect-redir-ssl.t 2017-01-22 07:00:26.511045123 -1000
@@ -27,6 +27,8 @@
my $redir_url;
+my $redir_url;
+
my $port;
$loop->SSL_listen(
host => "127.0.0.1",
@@ -81,6 +83,8 @@
$redir_url = "https://127.0.0.1:$port/moved";
+$redir_url = "https://127.0.0.1:$port/moved";
+
my $response;
$http->do_request(
@@ -102,6 +106,20 @@
# require_SSL
{
+ $http->configure( require_SSL => 1 );
+
+ $redir_url = "http://127.0.0.1:$port/moved_to_plaintext";
+
+ my $f = $http->GET( "https://127.0.0.1:$port/redir" );
+
+ wait_for { $f->is_ready };
+
+ ok( $f->failure, '->GET on http with require_SSL fails' );
+ like( scalar $f->failure, qr/require_SSL/, 'require_SSL failure' );
+}
+
+# require_SSL
+{
$http->configure( require_SSL => 1 );
$redir_url = "http://127.0.0.1:$port/moved_to_plaintext";