Struct crux_http::middleware::Redirect
source · 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
caps.http
.get("https://httpbin.org/redirect/2")
.middleware(crux_http::middleware::Redirect::default())
.send(Event::ReceiveResponse)
Trait Implementations§
source§impl Middleware for Redirect
impl Middleware for Redirect
source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
req: 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,
req: 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 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