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

pub struct Redirect { /* fields omitted */ }
Expand description

A middleware which attempts to follow HTTP redirects.

Implementations

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

Formats the value using the given formatter. Read more

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

Asynchronously handle the request, and return a response.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more