Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Setting $ua->max_redirect(0) didn't work [RT#40260]

  • Loading branch information...
commit 7f540e237d406192f6ee5c7d8dbdbb1b61266b12 1 parent 2dd7eae
@gisle authored
Showing with 12 additions and 15 deletions.
  1. +5 −14 lib/LWP/UserAgent.pm
  2. +7 −1 t/local/http.t
View
19 lib/LWP/UserAgent.pm
@@ -261,21 +261,12 @@ sub request
my($self, $request, $arg, $size, $previous) = @_;
my $response = $self->simple_request($request, $arg, $size);
+ $response->previous($previous) if $previous;
- if ($previous) {
- $response->previous($previous);
-
- # Check for loop in the redirects, we only count
- my $count = 0;
- my $r = $response;
- while ($r) {
- if (++$count > $self->{max_redirect}) {
- $response->header("Client-Warning" =>
- "Redirect loop detected (max_redirect = $self->{max_redirect})");
- return $response;
- }
- $r = $r->previous;
- }
+ if ($response->redirects >= $self->{max_redirect}) {
+ $response->header("Client-Warning" =>
+ "Redirect loop detected (max_redirect = $self->{max_redirect})");
+ return $response;
}
if (my $req = $self->run_handlers("response_redirect", $response)) {
View
8 t/local/http.t
@@ -48,7 +48,7 @@ else {
}
use Test;
-plan tests => 47;
+plan tests => 49;
my $greeting = <DAEMON>;
$greeting =~ /(<[^>]+>)/;
@@ -212,6 +212,12 @@ ok($res->is_redirect);
ok($res->header("Client-Warning"), qr/loop detected/i);
ok($res->redirects, 5);
+$ua->max_redirect(0);
+$res = $ua->request($req);
+ok($res->previous, undef);
+ok($res->redirects, 0);
+$ua->max_redirect(5);
+
#----------------------------------------------------------------
print "Check basic authorization...\n";
sub httpd_get_basic
Please sign in to comment.
Something went wrong with that request. Please try again.