Skip to content

Commit

Permalink
Fix redirect limited(0) should not follow redirects (#1645)
Browse files Browse the repository at this point in the history
Closes #1639
  • Loading branch information
phankydn committed Oct 10, 2022
1 parent 4c37766 commit 110c3ae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/redirect.rs
Expand Up @@ -128,7 +128,7 @@ impl Policy {
match self.inner {
PolicyKind::Custom(ref custom) => custom(attempt),
PolicyKind::Limit(max) => {
if attempt.previous.len() == max {
if attempt.previous.len() >= max {
attempt.error(TooManyRedirects)
} else {
attempt.follow()
Expand Down Expand Up @@ -277,6 +277,18 @@ fn test_redirect_policy_limit() {
}
}

#[test]
fn test_redirect_policy_limit_to_0() {
let policy = Policy::limited(0);
let next = Url::parse("http://x.y/z").unwrap();
let previous = vec![Url::parse("http://a.b/c").unwrap()];

match policy.check(StatusCode::FOUND, &next, &previous) {
ActionKind::Error(err) if err.is::<TooManyRedirects>() => (),
other => panic!("unexpected {:?}", other),
}
}

#[test]
fn test_redirect_policy_custom() {
let policy = Policy::custom(|attempt| {
Expand Down

0 comments on commit 110c3ae

Please sign in to comment.