-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(rpc): add compression to JSON-RPC #12352
feat(rpc): add compression to JSON-RPC #12352
Conversation
13c891e
to
c4c228f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, but I think hyper doesn't apply any changes to the body automatically so we'd need to do that
this seems relevant:
Thanks!! figured out that reth has in the case of this: paritytech/jsonrpsee#1133 (comment), the implementation is quite similar to what i did here but i will need to modify the body in order to compress it. this will be the only change i will probably need to make if i use tower compression layer implementation. use tower_http::compression::CompressionLayer;
impl<RpcMiddleware> RpcServerConfig<RpcMiddleware> {
//.....other middlewares
/// Returns a [`CompressionLayer`] that adds compression support (gzip, deflate, brotli, zstd)
/// based on the client's `Accept-Encoding` header
const fn maybe_compression_layer() -> Option<CompressionLayer> {
Some(CompressionLayer::new())
}
} wdyt ? |
cool, sgtm! |
cc @mattsse . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
only have pedantic style nits
Description
Resolves: #9652
This adds a compression layer that wraps
tower_http::compression::CompressionLayer
and adapts it to work with jsonrpsee's HTTP types. The layer automatically compresses responses based on the client'sAccept-Encoding
header while preserving the middleware chain's expected body type.Supports:
gzip
deflate
brotli
zstd
Demo