Struct reqwest::RedirectPolicy
[−]
[src]
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.
Methods
impl RedirectPolicy
[src]
pub fn limited(max: usize) -> RedirectPolicy
[src]
Create a RedirectPolicy with a maximum number of redirects.
A Error::TooManyRedirects
will be returned if the max is reached.
pub fn none() -> RedirectPolicy
[src]
Create a RedirectPolicy that does not follow any redirect.
pub fn custom<T>(policy: T) -> RedirectPolicy where
T: Fn(&Url, &[Url]) -> Result<bool> + Send + Sync + 'static,
[src]
T: Fn(&Url, &[Url]) -> Result<bool> + Send + Sync + 'static,
Create a custom RedirectPolicy using the passed function.
Note
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.
There are variants on ::Error
for both cases that can be used as
return values.
Example
client.redirect(RedirectPolicy::custom(|next, previous| { if previous.len() > 5 { Err(reqwest::Error::TooManyRedirects) } else if next.host_str() == Some("example.domain") { // prevent redirects to 'example.domain' Ok(false) } else { Ok(true) } }));
Trait Implementations
impl Debug for RedirectPolicy
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Default for RedirectPolicy
[src]
fn default() -> RedirectPolicy
[src]
Returns the "default value" for a type. Read more