Skip to content

Conversation

@paulcrussell
Copy link

πŸ”— Linked issue

#3077

❓ 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

The build process produces compressed public assets based on nitro option 'compressPublicAssets' if those assets are present then it means the response may 'Vary' based on Accept-Encoding request header.

Currently the 'Vary' based on Accept-Encoding request header is included only if the Accept-Encoding request header exists. This introduces a problem that the Vary header can get omitted if the client sends a request without Accept-Encoding header. This would cause the server to respond with a uncompressed file that would then be cached in shared caches and served to everyone.

Shifting the logic so that the header is always sent if the server is optionally configured to return uncompressed, gz or br public assets removes the possibility for a client to poison the cache for all.

Resolves #3077

πŸ“ Checklist

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

@paulcrussell paulcrussell requested a review from pi0 as a code owner July 3, 2025 16:45
@paulcrussell paulcrussell force-pushed the fix/content-negotiation branch from fb0e772 to cb2599c Compare July 4, 2025 12:28
@paulcrussell
Copy link
Author

@pi0 I've updated the commit to fix the failing tests.

@pi0 pi0 changed the title fix(content-negotiation) respect encoding file presence for Vary header fix(static): always add vary: accept-encoding for compressed assets Jul 14, 2025
@vercel
Copy link

vercel bot commented Dec 16, 2025

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

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this got delayed and thanks for adding tests!

I have locally investigated. We can reduce runtime overhead (of iteration and resolving for all static assets) by instead, flagging static assets that have a compressed variant with encoding: null build-time and then add vary header for them. It will cover tests.

@pi0 pi0 changed the title fix(static): always add vary: accept-encoding for compressed assets fix(static): add vary: accept-encoding for assets with compressed version Dec 16, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 16, 2025

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro/nitropack@3443

commit: 5f24a94

@pi0 pi0 merged commit 67f152c into nitrojs:v2 Dec 16, 2025
5 of 6 checks passed
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.

2 participants