=== modified file 'lib/Net/Async/HTTP.pm'
--- lib/Net/Async/HTTP.pm 2017-02-27 01:01:13 +0000
+++ lib/Net/Async/HTTP.pm 2018-04-02 17:14:30 +0000
@@ -799,13 +799,13 @@
my $self = shift;
( $response ) = @_;
- return $on_header->( $response ) unless $response->is_redirect;
-
# Consume and discard the entire body of a redirect
return sub {
return if @_;
return $response;
- };
+ } if $redirects and $response->is_redirect;
+
+ return $on_header->( $response );
} ),
);
} ),
=== modified file 't/11response-streaming.t'
--- t/11response-streaming.t 2018-04-02 15:43:52 +0000
+++ t/11response-streaming.t 2018-04-02 17:14:30 +0000
@@ -179,4 +179,41 @@
wait_for { $body_is_done };
}
+# on_header should see a redirect once we run out of indirections (RT124920)
+{
+ my $header;
+
+ $http->do_request(
+ uri => URI->new( "
http://my.server.here/" ),
+ max_redirects => 1,
+
+ on_header => sub {
+ ( $header ) = @_;
+ return sub {};
+ },
+ on_error => sub { die "Test died early - $_[0]" },
+ );
+
+ # Wait for request but don't really care what it actually is
+ my $request_stream = "";
+ wait_for_stream { $request_stream =~ m/$CRLF$CRLF/ } $peersock => $request_stream;
+
+ $peersock->syswrite( "HTTP/1.1 301 Moved Permanently$CRLF" .
+ "Content-Length: 0$CRLF" .
+ "Location:
http://my.server.here/elsewhere$CRLF" .
+ "Connection: Keep-Alive$CRLF" .
+ "$CRLF" );
+
+ $request_stream = "";
+ wait_for_stream { $request_stream =~ m/$CRLF$CRLF/ } $peersock => $request_stream;
+
+ $peersock->syswrite( "HTTP/1.1 301 Moved Permanently$CRLF" .
+ "Content-Length: 0$CRLF" .
+ "Location:
http://my.server.here/try-again$CRLF" .
+ "Connection: Keep-Alive$CRLF" .
+ "$CRLF" );
+
+ wait_for { defined $header };
+}
+
done_testing;