-
-
Notifications
You must be signed in to change notification settings - Fork 37
feat: zstd support
#2910
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: zstd support
#2910
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds Zstandard (zstd) compression support and centralizes zlib usage: new getSupportedFormats(), zstd handling in CompressionStream/DecompressionStream/fetchNodeHttp, fallback encoding update in server utils, and a changeset documenting patches and the feature. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant FetchLayer
participant zlib
Client->>Server: Request (Accept-Encoding: zstd, br, gzip)
Server->>FetchLayer: choose CompressionStream('zstd')
FetchLayer->>zlib: zlib.createZstdCompress()
zlib-->>FetchLayer: Compression stream
FetchLayer-->>Server: compressed response stream
Server-->>Client: send zstd-compressed response
Client->>Server: receives zstd-compressed response
Server->>FetchLayer: DecompressionStream('zstd')
FetchLayer->>zlib: zlib.createZstdDecompress()
zlib-->>FetchLayer: Decompression stream
FetchLayer-->>Server: decompressed data
Server-->>Client: deliver decompressed payload
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code graph analysis (3)packages/node-fetch/src/utils.ts (1)
packages/node-fetch/src/CompressionStream.ts (3)
packages/node-fetch/src/DecompressionStream.ts (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
🔇 Additional comments (11)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 Snapshot Release (
|
| Package | Version | Info |
|---|---|---|
@whatwg-node/node-fetch |
0.8.3-alpha-20251110163100-4652b77de1cf710e75445db45d91cdf62127a39f |
npm ↗︎ unpkg ↗︎ |
@whatwg-node/server |
0.10.16-alpha-20251110163100-4652b77de1cf710e75445db45d91cdf62127a39f |
npm ↗︎ unpkg ↗︎ |
✅
|
✅
|
✅
|
✅
|
✅
|
✅
|
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/node-fetch/src/fetchNodeHttp.ts (1)
39-39: Critical: Add 'zstd' to the accept-encoding header.The accept-encoding header needs to include 'zstd' to advertise client support for Zstandard compression. Without this, servers won't send zstd-compressed responses even though the client can now decompress them.
Apply this diff to add zstd to the accept-encoding header:
- nodeHeaders['accept-encoding'] ||= 'gzip, deflate, br'; + nodeHeaders['accept-encoding'] ||= 'gzip, deflate, br, zstd';
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/pink-sites-trade.md(1 hunks)packages/node-fetch/src/CompressionStream.ts(3 hunks)packages/node-fetch/src/DecompressionStream.ts(2 hunks)packages/node-fetch/src/fetchNodeHttp.ts(2 hunks)packages/server/src/utils.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-01-29T19:45:36.028Z
Learnt from: ardatan
Repo: ardatan/whatwg-node PR: 0
File: :0-0
Timestamp: 2025-01-29T19:45:36.028Z
Learning: The node-fetch package tries different fetch implementations in the following order: 1) node-libcurl 2) undici 3) built-in undici in Node 4) node:http as fallback
Applied to files:
.changeset/pink-sites-trade.mdpackages/node-fetch/src/fetchNodeHttp.ts
🧬 Code graph analysis (1)
packages/node-fetch/src/DecompressionStream.ts (1)
packages/node-fetch/src/CompressionStream.ts (1)
PonyfillCompressionFormat(4-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
- GitHub Check: server (native)
- GitHub Check: server (uws)
- GitHub Check: node-fetch (consumeBody)
- GitHub Check: node-fetch (noConsumeBody)
- GitHub Check: server (ponyfill)
- GitHub Check: server (undici)
- GitHub Check: e2e / cloudflare-modules
- GitHub Check: e2e / cloudflare-workers
- GitHub Check: e2e / aws-lambda
- GitHub Check: unit / node 18
- GitHub Check: unit / node 20
- GitHub Check: unit / bun
- GitHub Check: unit / node 25
- GitHub Check: unit / node 24
- GitHub Check: unit / deno
🔇 Additional comments (5)
.changeset/pink-sites-trade.md (1)
1-6: LGTM!The changeset documentation correctly identifies the affected packages and clearly describes the new zstd support feature.
packages/server/src/utils.ts (1)
525-531: Addition of zstd encoding looks correct.The 'zstd' encoding is properly added to the list of possible encodings and will be tested for support at runtime along with the other compression formats.
packages/node-fetch/src/fetchNodeHttp.ts (1)
4-4: Import refactor and zstd decompression support look correct.The switch from named imports to the default zlib import is applied consistently, and the zstd decompression case follows the same pattern as the existing compression formats.
Also applies to: 78-93
packages/node-fetch/src/CompressionStream.ts (1)
1-1: Import refactor and zstd compression support implemented correctly.The default zlib import is used consistently, and the zstd compression case properly integrates with the existing compression format handling.
Also applies to: 10-11, 27-41
packages/node-fetch/src/DecompressionStream.ts (1)
1-1: Import refactor and zstd decompression support implemented correctly.The default zlib import and zstd decompression case are consistent with the compression stream implementation. Note that the same version check consideration from CompressionStream.ts applies here as well.
Also applies to: 12-12, 19-33
Fixes #2909