Skip Menu |

This queue is for tickets about the Net-Async-HTTP CPAN distribution.

Report information
The Basics
Id: 124920
Status: resolved
Priority: 0/
Queue: Net-Async-HTTP

People
Owner: Nobody in particular
Requestors: ilmari [...] ilmari.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.42



Subject: No way to get at a redirect response
Date: Mon, 26 Mar 2018 14:10:56 +0100
To: bug-Net-Async-HTTP [...] rt.cpan.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
In the on_header callback passed by _do_request() to _do_one_request() only calls $on_header if the response is not a redirect. This makes it discard any redirect response even if we exhaust max_redirects, making it impossible to handle redirects oneself by setting max_redirects=>0. - ilmari -- "I use RMS as a guide in the same way that a boat captain would use a lighthouse. It's good to know where it is, but you generally don't want to find yourself in the same spot." - Tollef Fog Heen
Patch attached. -- Paul Evans
Subject: rt124920.patch
=== 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;