[−][src]Struct reqwest::RedirectPolicy
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]
impl RedirectPolicy
pub fn limited(max: usize) -> RedirectPolicy
[src]
pub fn limited(max: usize) -> RedirectPolicy
Create a RedirectPolicy with a maximum number of redirects.
An Error
will be returned if the max is reached.
pub fn none() -> RedirectPolicy
[src]
pub fn none() -> RedirectPolicy
Create a RedirectPolicy that does not follow any redirect.
pub fn custom<T>(policy: T) -> RedirectPolicy where
T: Fn(RedirectAttempt) -> RedirectAction + Send + Sync + 'static,
[src]
pub fn custom<T>(policy: T) -> RedirectPolicy where
T: Fn(RedirectAttempt) -> RedirectAction + 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.
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
.
Example
let custom = RedirectPolicy::custom(|attempt| { if attempt.previous().len() > 5 { attempt.too_many_redirects() } else if attempt.url().host_str() == Some("example.domain") { // prevent redirects to 'example.domain' attempt.stop() } else { attempt.follow() } }); let client = reqwest::Client::builder() .redirect(custom) .build()?;
pub fn redirect(&self, attempt: RedirectAttempt) -> RedirectAction
[src]
pub fn redirect(&self, attempt: RedirectAttempt) -> RedirectAction
Apply this policy to a given [RedirectAttempt
] to produce a [RedirectAction
].
Note
This method can be used together with RedirectPolicy::custom() to construct one RedirectPolicy that wraps another.
Example
let custom = RedirectPolicy::custom(|attempt| { eprintln!("{}, Location: {:?}", attempt.status(), attempt.url()); RedirectPolicy::default().redirect(attempt) });
Trait Implementations
impl Debug for RedirectPolicy
[src]
impl Debug for RedirectPolicy
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Default for RedirectPolicy
[src]
impl Default for RedirectPolicy
fn default() -> RedirectPolicy
[src]
fn default() -> RedirectPolicy
Returns the "default value" for a type. Read more
Auto Trait Implementations
impl Send for RedirectPolicy
impl Send for RedirectPolicy
impl Sync for RedirectPolicy
impl Sync for RedirectPolicy
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
ⓘImportant traits for &'a mut Rfn borrow(&self) -> &T
[src]
fn borrow(&self) -> &T
Immutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
ⓘImportant traits for &'a mut Rfn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Erased for T
[src]
impl<T> Erased for T