pub trait AsyncInterceptor {
type Future: Future<Output = Result<Request<()>, Status>>;
// Required method
fn call(&mut self, request: Request<()>) -> Self::Future;
}
Expand description
An async gRPC interceptor.
This interceptor is an async
variant of Tonic’s built-in [Interceptor
].
gRPC interceptors are similar to middleware but have less flexibility. An interceptor allows
you to do two main things, one is to add/remove/check items in the MetadataMap
of each
request. Two, cancel a request with a Status
.
Any function that satisfies the bound async FnMut(Request<()>) -> Result<Request<()>, Status>
can be used as an AsyncInterceptor
.
An interceptor can be used on both the server and client side through the tonic-build
crate’s
generated structs.
See the interceptor example for more details.
If you need more powerful middleware, tower is the recommended approach. You can find examples of how to use tower with tonic here.
Additionally, interceptors is not the recommended way to add logging to your service. For that
a tower middleware is more appropriate since it can also act on the response. For example
tower-http’s Trace
middleware supports gRPC out of the box.
Async version of Interceptor
.