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

source

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 Debug for Redirect

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Redirect

source§

fn default() -> Self

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

source§

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,

Asynchronously handle the request, and return a response.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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

source§

fn vzip(self) -> V