Trait tonic_middleware::Middleware
source · pub trait Middleware<S>where
S: ServiceBound,{
// Required method
fn call<'life0, 'async_trait>(
&'life0 self,
req: Request<BoxBody>,
service: S,
) -> Pin<Box<dyn Future<Output = Result<Response<BoxBody>, S::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
The Middleware
trait defines a generic interface for middleware components
in a grpc service chain.
Implementors of this trait can modify, observe, or otherwise interact with requests and
responses in the service pipeline
If you need just intercept requests, pls can [RequestInterceptor]
§Type Parameters
S
: A service bound that defines the requirements for the service being wrapped by the middleware.
Required Methods§
sourcefn call<'life0, 'async_trait>(
&'life0 self,
req: Request<BoxBody>,
service: S,
) -> Pin<Box<dyn Future<Output = Result<Response<BoxBody>, S::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn call<'life0, 'async_trait>(
&'life0 self,
req: Request<BoxBody>,
service: S,
) -> Pin<Box<dyn Future<Output = Result<Response<BoxBody>, S::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Processes an incoming request and forwards it to the given service.
Implementations may perform operations before or after forwarding the request, such as logging, metrics collection, or request modification.
§Parameters
req
: The incoming request to process.service
: The service to forward the processed request to.
§Returns
A Result
containing the response from the service or an error if one occurred
during processing.