Interceptors
There are scenarios where you may want the ability to inject in metadata before sending a request to a gRPC server. Another possible requirement is that you need to reject a request to a server based on some prerequisite such as authentication. In both of these scenarios you might use a pattern called “middleware”. A very common feature of application frameworks like Ruby on Rails is the ability to add and modify a middleware stack. This includes checking sessions, CSRF protection, or even just compressing the response body before sending it back.
In the gRPC world this functionality is called “interceptors”. An interceptor allows a client or server to wrap RPC requests and responses. This includes streaming and unary RPC calls as well. An interceptor has the ability to manipulate almost everything about a procedure call, but is more commonly used for wrapping around logic for things such as authentication, metrics, distributed tracing, etc.
The...