-
Notifications
You must be signed in to change notification settings - Fork 172
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
Pass something from http middleware to rpc middleware #1370
Comments
Hey hey, Have you looked at this example which does passes the HTTP headers to the RPC middleware stuff. But you are right that it won't work with server builder API instead you have to utilize the "low-level API" and use jsonrpsee as as tower service and start the hyper server yourself. Another example how we are using it in substrate to disable/enable rpc rate limiting middleware... I hope that helps... |
Thanks! This is a bit mindbending. Do I understand correctly that the approach here is to create an rpc service for every http connection, kinda? |
Yes, if you want some state from HTTP request itself such as headers then it's only possible to utilize it by creating a rpc service per connection. So I get that it's quite tricky to use/understand but that's the trade-off right because we didn't want to introduce any additional custom middleware stuff in jsonrpsee and clone stuff that may not used by users.... |
You can pass data from HTTP to RPC with request extensions. In this example we parse client identification in the HTTP layer and use it in the RPC layer. |
I might have missed something, but I don't see a way to pass anything from http middlware to rpc middleware/handler.
I'd like to do authorization over http request, and then depending on the result possibly each rpc would enable/disable certain things etc.
Conceptually it's easy, but there seem to be nothing the two layers together, so it can't be done.
The text was updated successfully, but these errors were encountered: