Fix redirect limited(0) should not follow redirects (#1645)

Closes #1639
This commit is contained in:
anhcuky
2022-10-10 22:46:31 +07:00
committed by GitHub
parent 4c377661bb
commit 110c3aee33

View File

@@ -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()
@@ -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| {