feat: add zstd content-encoding decompression support#6837
Closed
StilesCrisis wants to merge 2 commits into
Closed
feat: add zstd content-encoding decompression support#6837StilesCrisis wants to merge 2 commits into
StilesCrisis wants to merge 2 commits into
Conversation
…ncoding header When a fetch() subrequest returns Content-Encoding: zstd, workerd now: 1. Decompresses the body transparently via a new ZstdAsyncInputStream class 2. Strips the Content-Encoding header from the Response so downstream code (e.g. Cache API) doesn't re-interpret the already-decoded body as zstd This mirrors the existing gzip and brotli auto-decode behavior. Adds ZSTD to the StreamEncoding capnp enum, implements ZstdAsyncInputStream using the zstd streaming API in both system-streams.c++ and readable-source.c++, and adds KJ_FAIL_REQUIRE for the unsupported zstd output compression path. Fixes: cloudflare#5112 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds 4 readable-source tests and 2 writable-sink tests mirroring the existing gzip test suite: - Zstd encoded stream (readAllBytes) - Zstd encoded stream (pumpTo) - Zstd encoded stream (pumpTo same encoding passthrough) - Zstd encoded stream (pumpTo different encoding → gzip) - Zstd-encoding sink (throws for unsupported output compression) - Zstd-encoding sink (identity passthrough via disownEncodingResponsibility) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
2 tasks
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.
Summary
Before this PR, responses with
Content-Encoding: zstdwere passed through as raw compressed bytes — workerd had no zstd decompression support. Workers calling.text(),.json(), etc. on such responses received garbled data.ZstdAsyncInputStreamstreaming decompressor insystem-streams.c++andreadable-source.c++, modeled after the existing gzip/brotli implementations"zstd"intogetContentEncoding()so the encoding is recognised and the body is auto-decodedzstd @3to theStreamEncodingcapnp enumKJ_FAIL_REQUIREfor the unsupported zstd output-compression path inEncodedAsyncOutputStreamFollow-up hardening (compat flag, DevTools inspector, empty-body edge case, RPC robustness) is in a separate PR stacked on top of this one.
Test plan
system-streams-test:ZstdAsyncInputStream decompresses correctlyreadable-source-test:Zstd encoded stream,(pumpTo),(pumpTo same encoding),(pumpTo different encoding)writable-sink-test:Zstd-encoding sink,Zstd-encoding sink (identity)server-test:Server: encodeResponseBody: zstd response body is decompressed🤖 Generated with Claude Code