pub struct RedirectPolicy { /* fields omitted */ }
A type that controls the policy on how to handle the following of redirects.
The default value will catch redirect loops, and has a maximum of 10
redirects it will follow in a chain before returning an error.
Create a RedirectPolicy with a maximum number of redirects.
An Error
will be returned if the max is reached.
Create a RedirectPolicy that does not follow any redirect.
Create a custom RedirectPolicy using the passed function.
The default RedirectPolicy handles redirect loops and a maximum loop
chain, but the custom variant does not do that for you automatically.
The custom policy should have some way of handling those.
Information on the next request and previous requests can be found
on the RedirectAttempt
argument passed to the closure.
Actions can be conveniently created from methods on the
RedirectAttempt
.
let custom = RedirectPolicy::custom(|attempt| {
if attempt.previous().len() > 5 {
attempt.too_many_redirects()
} else if attempt.url().host_str() == Some("example.domain") {
attempt.stop()
} else {
attempt.follow()
}
});
let client = reqwest::Client::builder()
.redirect(custom)
.build()?;
Apply this policy to a given [RedirectAttempt
] to produce a [RedirectAction
].
This method can be used together with RedirectPolicy::custom()
to construct one RedirectPolicy that wraps another.
let custom = RedirectPolicy::custom(|attempt| {
eprintln!("{}, Location: {:?}", attempt.status(), attempt.url());
RedirectPolicy::default().redirect(attempt)
});
Returns the "default value" for a type. Read more
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static