Trait tonic_middleware::RequestInterceptor

source ·
pub trait RequestInterceptor {
    // Required method
    fn intercept<'life0, 'async_trait>(
        &'life0 self,
        req: Request<Body>
    ) -> Pin<Box<dyn Future<Output = Result<Request<Body>, Status>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

The RequestInterceptor trait is designed to enable the interception and processing of incoming requests within your service pipeline. This trait is particularly useful for performing operations such as authentication, enriching requests with additional metadata, or rejecting requests based on certain criteria before they reach the service logic. If your requirements extend beyond request interception, and you need to interact with both the request and response or to perform actions after the service call has been made, you should consider implementing Middleware.

See examples on GitHub

Required Methods§

source

fn intercept<'life0, 'async_trait>( &'life0 self, req: Request<Body> ) -> Pin<Box<dyn Future<Output = Result<Request<Body>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Intercepts an incoming request, allowing for inspection, modification, or early rejection with a Status error.

§Parameters
  • req: The incoming Request to be intercepted.
§Returns

Returns either the potentially modified request for further processing, or a Status error to halt processing with a specific error response.

Implementors§