Trait tonic_middleware::RequestInterceptor
source · pub trait RequestInterceptor {
// Required method
fn intercept<'life0, 'async_trait>(
&'life0 self,
req: Request<BoxBody>,
) -> Pin<Box<dyn Future<Output = Result<Request<BoxBody>, 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
.
Required Methods§
sourcefn intercept<'life0, 'async_trait>(
&'life0 self,
req: Request<BoxBody>,
) -> Pin<Box<dyn Future<Output = Result<Request<BoxBody>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn intercept<'life0, 'async_trait>(
&'life0 self,
req: Request<BoxBody>,
) -> Pin<Box<dyn Future<Output = Result<Request<BoxBody>, 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 incomingRequest
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.