nitro icon indicating copy to clipboard operation
nitro copied to clipboard

`/public/[filename].gz` missing `Content-Encoding: gzip` Header

Open OrbisK opened this issue 7 months ago • 2 comments

Environment

https://stackblitz.com/edit/github-r5nvmagd?file=server%2Froutes%2Findex.ts,server%2Fpublic%2Fnitro.js

Reproduction

https://stackblitz.com/edit/github-r5nvmagd?file=server%2Froutes%2Findex.ts,server%2Fpublic%2Fnitro.js

  1. run reproduction
  2. open network tab
  3. inspect .gz file response headers in network tab

Describe the bug

Reproduced https://github.com/nuxt/nuxt/issues/26420 in nitro-only

Additional context

No response

Logs


OrbisK avatar May 30 '25 16:05 OrbisK

Although I created https://github.com/nitrojs/nitro/pull/3381, I'm now unsure if Content-Encoding: gzip should be automatically added for .gz files.

This header would cause the browser to unzip the file. It might be useful in your scenarios where you want to use the JS content directly in the browser, but what if the user wants to download the raw .gz file? The browser will always unzip the file with this header before saving it to disk.

kricsleo avatar Jun 02 '25 04:06 kricsleo

Perhaps we should give the user the option of whether or not to inject headers. We could add a publicApplyHeader function to apply headers via configuration.

OrbisK avatar Jun 02 '25 06:06 OrbisK