pub struct Redirect { /* private fields */ }Expand description
A middleware which attempts to follow HTTP redirects.
Implementations§
Source§impl Redirect
impl Redirect
Sourcepub fn new(attempts: u8) -> Self
pub fn new(attempts: u8) -> Self
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
Http::get("https://httpbin.org/redirect/2")
.middleware(crux_http::middleware::Redirect::default())
.build()
.then_send(Event::ReceiveResponse);Trait Implementations§
Source§impl Middleware for Redirect
impl Middleware for Redirect
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
request: Request,
client: Client,
next: Next<'life1>,
) -> Pin<Box<dyn Future<Output = Result<ResponseAsync>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
request: Request,
client: Client,
next: Next<'life1>,
) -> Pin<Box<dyn Future<Output = Result<ResponseAsync>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Asynchronously handle the request, and return a response.
Auto Trait Implementations§
impl Freeze for Redirect
impl RefUnwindSafe for Redirect
impl Send for Redirect
impl Sync for Redirect
impl Unpin for Redirect
impl UnsafeUnpin for Redirect
impl UnwindSafe for Redirect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more