Middleware

Trait Middleware 

Source
pub trait Middleware:
    Debug
    + Send
    + Sync
    + 'static {
    // Required method
    fn apply<'life0, 'life1, 'async_trait>(
        self: Pin<&'life0 Self>,
        request: Request,
        next: Next<'life1>,
    ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

An HTTP request/response modifier.

This sits between the raw request and response and the endpoint, allowing custom functions to mutate either before being passed on. A typical middleware will take the incoming Request, potentially modify it, before calling Next::apply with the modified request; then, take the resulting Response, potentially modifying it, before returning. However, since every layer of the stack is fallible, it must be able to handle errors.

Required Methods§

Source

fn apply<'life0, 'life1, 'async_trait>( self: Pin<&'life0 Self>, request: Request, next: Next<'life1>, ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Handles the given request, returning a response. The next parameter contains the information on how to process everything after the current middleware, i.e. generating a response from the endpoint.

Implementors§

Source§

impl Middleware for CookieMiddleware

Available on crate feature cookie only.
Source§

impl Middleware for TraceMiddleware

Source§

impl<T: Clone + Send + Sync + 'static> Middleware for StateMiddleware<T>