Skip to content
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 response contexts from RPC middleware to HTTP middleware #1509

Open
shunsukew opened this issue Dec 27, 2024 · 2 comments
Open

Pass response contexts from RPC middleware to HTTP middleware #1509

shunsukew opened this issue Dec 27, 2024 · 2 comments

Comments

@shunsukew
Copy link

shunsukew commented Dec 27, 2024

I am developing a rate-limiting RPC middleware. Currently, jsonrpsee framework utilizes MethodResponse Extensions in the RPC layer and http::Response Extensions in the HTTP layer, with these extensions operating independently of each other.

I would like to propagate context information from the RPC layer to the HTTP layer to achieve functionality such as returning a status code other than 200 (429 in my case) or, at the very least, adding an HTTP header to indicate rate limiting based on data in contexts.

What would be the best approach to transfer context (Extensions) information from a jsonrpsee RPC middleware to a hyper HTTP middleware?

@shunsukew shunsukew changed the title Pass context from RPC middleware to HTTP middleware Pass response context from RPC middleware to HTTP middleware Dec 27, 2024
@shunsukew shunsukew changed the title Pass response context from RPC middleware to HTTP middleware Pass response contexts from RPC middleware to HTTP middleware Dec 27, 2024
@niklasad1
Copy link
Member

I think we could copy the extensions from the MethodResponse to the HTTP response to fix that and then you would need some HTTP middleware to check whether some error occurred and set desired HTTP status code on the response.

This shouldn't be that hard to fix

@shunsukew
Copy link
Author

shunsukew commented Dec 29, 2024

That would be really helpful. Thank you so much.
A single RPC call functions as expected, however, batch responses may require merging extension data. Addressing potential conflicts of the same Type data across calls within a batch is a subject for discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants