feat(codec): Add ServerCompressionInterceptor for gRPC compression#2649
Open
sauravzg wants to merge 1 commit into
Open
feat(codec): Add ServerCompressionInterceptor for gRPC compression#2649sauravzg wants to merge 1 commit into
sauravzg wants to merge 1 commit into
Conversation
beb2595 to
5acb682
Compare
5acb682 to
b4af9e3
Compare
db718f9 to
2e65c81
Compare
⚠️ TRADEOFFS & LIMITATIONS⚠️ Due to the current limitations of the `RecvStream` API (which lacks out-of-band compression signals), this implementation introduces a high degree of coupling between the HTTP transport, compression, and serialization layers. Consequently, this design necessitates type erasure(IncomingRawMessage) and incurs a forced `Box` allocation penalty to function within the existing stream boundaries. This change introduces the `ServerCompressionInterceptor`, which integrates compression and decompression capabilities into the server-side gRPC request/response lifecycle. Key additions: - **`ServerCompressionInterceptor`**: Implements the `Intercept` trait to wrap incoming requests. It parses the `grpc-encoding` and `grpc-accept-encoding` headers to determine the appropriate `Compressor` and `Decompressor` to use. - **Decompression Bomb Mitigation**: Protects against decompression bomb (zip bomb) attacks by strictly limiting writes during the decompression process. - **`CompressionResolver` Integration**: Uses a `CompressionResolver` registry to look up algorithms by name. - **Stream Wrapping**: Wraps the underlying `RecvStream` (to decompress incoming messages) and `SendStream` (to compress outgoing messages and inject the correct `grpc-encoding` header). - **Error Handling**: Returns standard gRPC status errors if an encoding is unsupported or if compression/decompression fails during stream processing. - **Unit Tests**: Includes a comprehensive suite of Tokio-based tests covering successful compression/decompression, unsupported encoding errors, registry lookup failures, and fallback mechanisms.
b4af9e3 to
bcfd493
Compare
2e65c81 to
c4d2db5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RecvStreamAPI (which lacks out-of-band compression signals), this implementation introduces a high degree of coupling between the HTTP transport, compression, and serialization layers. Consequently, this design necessitates type erasure(IncomingRawMessage) and incurs a forcedBoxallocation penalty to function within the existing stream boundaries.This change introduces the
ServerCompressionInterceptor, which integrates compression and decompression capabilities into the server-side gRPC request/response lifecycle.Key additions:
ServerCompressionInterceptor: Implements theIntercepttrait to wrap incoming requests. It parses thegrpc-encodingandgrpc-accept-encodingheaders to determine the appropriateCompressorandDecompressorto use.CompressionResolverIntegration: Uses aCompressionResolverregistry to look up algorithms by name.RecvStream(to decompress incoming messages) andSendStream(to compress outgoing messages and inject the correctgrpc-encodingheader).