Skip to main content

Middleware

Trait Middleware 

Source
pub trait Middleware: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn before_request<'life0, 'life1, 'async_trait>(
        &'life0 self,
        req: &'life1 AuthRequest,
    ) -> Pin<Box<dyn Future<Output = AuthResult<Option<AuthResponse>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn after_request<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _req: &'life1 AuthRequest,
        response: AuthResponse,
    ) -> Pin<Box<dyn Future<Output = AuthResult<AuthResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Middleware trait for request/response processing.

Middleware runs before plugin dispatch (before_request) and after a response has been produced (after_request).

Required Methods§

Source

fn name(&self) -> &'static str

Human-readable name for logging / debugging.

Source

fn before_request<'life0, 'life1, 'async_trait>( &'life0 self, req: &'life1 AuthRequest, ) -> Pin<Box<dyn Future<Output = AuthResult<Option<AuthResponse>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called before the request is dispatched to plugins.

Return Ok(Some(response)) to short-circuit (e.g. block the request). Return Ok(None) to continue processing.

Provided Methods§

Source

fn after_request<'life0, 'life1, 'async_trait>( &'life0 self, _req: &'life1 AuthRequest, response: AuthResponse, ) -> Pin<Box<dyn Future<Output = AuthResult<AuthResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called after a response has been produced.

Allows the middleware to mutate the response (e.g. add CORS headers). The default implementation is a no-op pass-through.

Implementors§