Skip to content

fix(runtime): respect identity and wildcard Accept-Encoding preferences - #5189

Closed
MilindChatrabhuji wants to merge 1 commit into
nitrojs:mainfrom
MilindChatrabhuji:fix/static-accept-encoding-5158
Closed

MilindChatrabhuji wants to merge 1 commit into
nitrojs:mainfrom
MilindChatrabhuji:fix/static-accept-encoding-5158

Conversation

@MilindChatrabhuji

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #5158

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Updates static asset Accept-Encoding negotiation in src/runtime/internal/static.ts to follow RFC 9110 §12.5.3 for identity and wildcard (*) preferences:

  • Tracks explicit identity and wildcard (*) weights in parseAcceptEncoding alongside named encodings (EncodingMap), preserving explicit q=0 exclusions (including identity;q=0 and *;q=0).
  • Applies wildcard weights to unmentioned supported encodings (including identity when identity is not explicitly specified), while explicit weights take precedence over *.
  • Preserves implicit identity as the lowest-preference fallback when neither identity nor * appears in Accept-Encoding, and breaks equal-weight ties in favor of compressed codings ahead of identity.
  • Returns 406 (with Cache-Control: no-store and Vary: Accept-Encoding when compressed variants exist) instead of 404 / falling through when hasAsset(id) is true and identity ("") was excluded alongside any other available representations.

Local verification (Windows 11, Node v22.14.0)

  • oxfmt --check src/runtime/internal/static.ts test/unit/static-middleware.test.ts — passed.
  • oxlint . — 0 errors (2 pre-existing triple-slash warnings in lib/vite.types.d.mts and lib/rsbuild.types.d.mts).
  • tsc --noEmit --skipLibCheck (after obuild --stub, scripts/gen-presets.ts, and obuild) — passed.
  • vitest run test/unit/static-middleware.test.ts test/unit/compress-assets.test.ts test/unit/preset-public-asset-cors.test.ts test/unit/assets-resolver.test.ts — 4 files, 75 tests passed (including 7 new negotiation & 406/404 regression cases).
  • vitest run test/minimal — 1 file, 24 tests passed.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel

vercel Bot commented Nov 28, 2026

Copy link
Copy Markdown

@MilindChatrabhuji is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@MilindChatrabhuji

Copy link
Copy Markdown
Contributor Author

Closing in favor of #5160, which was already opened for #5158 (I missed it during the initial search before opening).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static asset negotiation ignores identity and wildcard Accept-Encoding preferences

1 participant