Expose method name in `Interceptor`s
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
## Feature Request
### Crates
tonic
### Motivation
I need to attach a deadline/timeout whose value varies based on which method I'm calling. Additionally, I implement some metrics like counting number of reqs/method, etc. Currently I can implement these as `tower` middlewares which totally works, but it'd be nice to be able to use the much simpler `Interceptor` interface for something this simple.
### Proposal
A `uri()` method available on the Request object like in an `http::Request` would be the simplest. Beyond that, it might be nice to do something more gRPC specific, like `.method()` return a `GrpcMethod` type which exposes `.service()` and `.method()` functions.
This is to avoid this hullabaloo:
`let maybe_method = req.uri().to_string().rsplitn(2, '/').next()`
### Alternatives
Right now I'm solving this in tower middleware. This can also be solved by manually building `Request`s before calling the generated client code, and inserting the appropriate metadata then.
The proposal would I think be a bit more convenient in many cases, though. (As a bonus, even easier if there was a way for me to get a static reference to the `GrpcMethod` (or `&'static str`) which defines the RPC path, currently just baked as a literal into the client code)
Contributor guide
Assessment
This issue has not been assessed yet.