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
Asynchronously handle the request, and return a response.
Auto Trait Implementations
impl RefUnwindSafe for Redirect
impl UnwindSafe for Redirect
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
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