paritytech / jsonrpsee

Rust JSON-RPC library on top of async/await
MIT License
629 stars 169 forks source link

Inheriting HTTP Header Option to RPC middlewares #1388

Closed shunsukew closed 3 months ago

shunsukew commented 4 months ago

With the recent merge of PR #1305, different layers of rpc middleware can now share data using Extensions.

Leveraging this functionality, we plan to set HTTP header data within the Request extensions of an RPC middleware call, enabling subsequent middleware layers to process the header information effectively.

In our use case, we aim to log each RPC method call, associating specific HTTP header values with each entry. This includes logging individual lines for each call and multiple lines for batch calls. Additionally, this approach facilitates other scenarios, such as HTTP header validation on a per-RPC method basis.

This can be achieved by passing header information to this function and setting them to Extensions only when the option is enabled.


Using HTTP middleware is one possible approach. However, for websocket requests, the RPC middleware needs to propagate HTTP header as its context data to achieve similar functionality.

niklasad1 commented 4 months ago

You are basically suggesting to pass the extensions from HTTP request down to the rpc call such that you can access such thing in the rpc middleware?

Sure, let's do that

shunsukew commented 4 months ago

Thank you so much, yes exactly that’s what meant!