Skip to main content

PreRouteMiddleware

Trait PreRouteMiddleware 

Source
pub trait PreRouteMiddleware: Send + Sync {
    // Required method
    fn rewrite<'life0, 'async_trait>(
        &'life0 self,
        request: Request,
    ) -> Pin<Box<dyn Future<Output = Result<Request, HttpResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for middleware that runs before route matching.

Implement rewrite to inspect and/or rewrite the request path. The method receives ownership of the request and must return either the (possibly modified) request to continue routing, or an HttpResponse to short-circuit immediately.

Short-circuiting is appropriate for cases like unknown custom domains (return 404) where the request should never reach route matching.

Required Methods§

Source

fn rewrite<'life0, 'async_trait>( &'life0 self, request: Request, ) -> Pin<Box<dyn Future<Output = Result<Request, HttpResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Inspect and optionally rewrite the request before route matching.

  • Return Ok(request) to continue (with or without path rewrite via set_path).
  • Return Err(response) to short-circuit — the response is sent immediately and route matching is skipped.

Implementors§