Fix redirect limited(0) should not follow redirects (#1645)
Closes #1639
This commit is contained in:
@@ -128,7 +128,7 @@ impl Policy {
|
|||||||
match self.inner {
|
match self.inner {
|
||||||
PolicyKind::Custom(ref custom) => custom(attempt),
|
PolicyKind::Custom(ref custom) => custom(attempt),
|
||||||
PolicyKind::Limit(max) => {
|
PolicyKind::Limit(max) => {
|
||||||
if attempt.previous.len() == max {
|
if attempt.previous.len() >= max {
|
||||||
attempt.error(TooManyRedirects)
|
attempt.error(TooManyRedirects)
|
||||||
} else {
|
} else {
|
||||||
attempt.follow()
|
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]
|
#[test]
|
||||||
fn test_redirect_policy_custom() {
|
fn test_redirect_policy_custom() {
|
||||||
let policy = Policy::custom(|attempt| {
|
let policy = Policy::custom(|attempt| {
|
||||||
|
|||||||
Reference in New Issue
Block a user