-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow FnMut in Interceptor #372
Comments
Yeah, the idea was intentional since an interceptor can run on multiple tasks at once and on different threads. The solution is to go with the tower middleware but that isn't 100% simple. On the server side there is the hyper_warp example which shows how to work with services a bit. |
Thanks. I'll take a look at that example a little more closely and see how to best translate it for the client side. |
Let me know if you have any questions in discord and we can chat a bit more. |
@LucioFranco thanks for the offer. I'm still interested in trying to get something together and will reach out if I run into problems once I have a chance to get to this. Unfortunately, I ran into the classic problem of being able to get enough working that I haven't had the time to prioritize it further. The addition of the server-side example in #375 will also probably help as a guide. |
Looking at this a little more closely, there doesn't seem to be a clear way to access the underlying tower layers for the transport::Channel. The server side seems to have the into_service escape hatch that could be used to combine with server middleware. It does look like the Channel from the connect functions could be returned fairly easily, but I'm not sure if there's a specific API suggestion I would make at the moment. |
I wrote a json web token authorization interceptor based on the gcp example (super helpful, btw!). This let me use a service account key to authenticate with google services.
There was one thing that cam up in the process. Since Interceptor is built from Fn, rather than FnMut, I end up being forced to never reauthorizing the key (without tearing down the client) or reauthorizing the key every time.
Looking at the code for tonic::client::Grpc::streaming, it seems like it would be fairly straight-forward to add something like a IterceptorMut. However, from the docs, it sounds like this design was slightly intentional and that the most appropriate way of doing this would be a tower middleware.
Reading through the tonic and hyper docs/source, as well as #69 and #70, there doesn't seem to be
a clean way of hooking those in. Am I missing a better way of doing this? If not, is there a way you envisioned this happening? (It also might make more sense to look at this within hyper)
Happy to work through implementation if there's a general design that you'd want, or take a stab at the design if there's support for changing APIs around to support this feature.
The text was updated successfully, but these errors were encountered: