[][src]Struct reqwest::RedirectPolicy

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.

  • limited can be used have the same as the default behavior, but adjust the allowed maximum redirect hops in a chain.
  • none can be used to disable all redirect behavior.
  • custom can be used to create a customized policy.


impl RedirectPolicy[src]

pub fn limited(max: usize) -> RedirectPolicy[src]

Create a RedirectPolicy with a maximum number of redirects.

An Error 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(RedirectAttempt) -> RedirectAction + Send + Sync + 'static, 

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 {
    } else if attempt.url().host_str() == Some("example.domain") {
        // prevent redirects to 'example.domain'
    } else {
let client = reqwest::Client::builder()

pub fn redirect(&self, attempt: RedirectAttempt) -> RedirectAction[src]

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());

Trait Implementations

impl Default for RedirectPolicy[src]

impl Debug for RedirectPolicy[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> Any for T where
    T: 'static + ?Sized

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err

impl<T> Erased for T