Trait tonic::service::Interceptor
source · [−]Expand description
A gRPC 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 FnMut(Request<()>) -> Result<Request<()>, Status>
can be
used as an Interceptor
.
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.