Struct surf::middleware::Redirect[][src]

pub struct Redirect { /* fields omitted */ }

A middleware which attempts to follow HTTP redirects.

Implementations

impl Redirect[src]

pub fn new(attempts: u8) -> Self[src]

Create a new instance of the Redirect middleware, which attempts to follow redirects up to as many times as specified.

Consider using Redirect::default() for the default number of redirect attempts.

This middleware will follow redirects from the Location header if the server returns any of the following http response codes:

  • 301 Moved Permanently
  • 302 Found
  • 303 See other
  • 307 Temporary Redirect
  • 308 Permanent Redirect

Errors

An error will be passed through the middleware stack if the value of the Location header is not a validly parsing url.

Caveats

This will presently make at least one additional HTTP request before the actual request to determine if there is a redirect that should be followed, so as to preserve any request body.

Examples

let req = surf::get("https://httpbin.org/redirect/2");
let client = surf::client().with(surf::middleware::Redirect::new(5));
let mut res = client.send(req).await?;
dbg!(res.body_string().await?);

Trait Implementations

impl Debug for Redirect[src]

impl Default for Redirect[src]

fn default() -> Self[src]

Create a new instance of the Redirect middleware, which attempts to follow up to 3 redirects (not including the actual request).

impl Middleware for Redirect[src]

Auto Trait Implementations

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]