fix(static): handle weighted accept-encoding values - #4470
Conversation
|
@MFA-G is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe static middleware now normalizes ChangesAccept-Encoding support
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/internal/static.ts`:
- Line 24: Update the Accept-Encoding parsing in the encoding-selection map to
read each entry’s q parameter, exclude entries with q=0 before sorting or
selecting encodings, and preserve existing behavior for positive or omitted
quality values. Ensure requests such as gzip; q=0 do not select compressed
assets.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9fe0fe8c-eccc-4a8a-820e-cc488e89fde1
📒 Files selected for processing (2)
src/runtime/internal/static.tstest/unit/static-middleware.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/internal/static.ts`:
- Line 31: Normalize the trimmed Accept-Encoding token to lowercase before
indexing EncodingMap, so case variants such as GZIP, Br, and ZSTD resolve to the
existing encodings while preserving the current lookup flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 469981da-e6f6-408d-aa42-721b8405d1f0
📒 Files selected for processing (2)
src/runtime/internal/static.tstest/unit/static-middleware.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- test/unit/static-middleware.test.ts
Linked issue
Resolves #4457
Type of change
Description
Strip optional parameters from each
Accept-Encodingtoken before looking it up in the compressed-asset encoding map. This lets standard weighted values such asgzip; q=1.0andbr; q=0.9match their precompressed assets instead of silently falling back to the uncompressed file, matching the RFC 9110 grammar forAccept-Encoding.A focused unit regression test verifies that a weighted header selects the gzip asset and sets
Content-Encoding: gzip.Checklist
Validation
pnpm vitest run test/unit/static-middleware.test.ts(3 passed)pnpm lintpnpm stubpnpm typecheck