Subject: | do_request() - on_response still gets called with 4xx when fail_on_error => 1 |
Below, on_response() shouldn't be called since a 4xx is returned. I suspect this happens with 5xx as well.
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Async::Loop;
use Net::Async::HTTP;
use URI;
my $loop = IO::Async::Loop->new();
my $http = Net::Async::HTTP->new(
fail_on_error => 1,
);
$loop->add( $http );
$http->do_request(
uri => URI->new( "http://www.cpan.org/asdfasdf" ),
on_response => sub { print "Success: " . shift->as_string . "\n"; },
on_error => sub { print "Failure: " . shift . "\n" },
);
$loop->run;
__END__
mhorsfall@tworivers:~$ ./http-ex.pl
Success: HTTP/1.1 404 Not Found
Connection: close
Date: Mon, 09 Feb 2015 18:22:43 GMT
Server: Apache/2.2.15 (Red Hat)
Vary: Accept-Encoding
Content-Length: 285
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /asdfasdf was not found on this server.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at www.cpan.org Port 80</address>
</body></html>
Failure: 404 Not Found