Skip to content

fix: should not set "Content-Encoding" for a direct request of a compressed file#161

Open
hi-ogawa wants to merge 5 commits intolukeed:mainfrom
hi-ogawa:fix-158-content-encoding-only-for-accept-encoding
Open

fix: should not set "Content-Encoding" for a direct request of a compressed file#161
hi-ogawa wants to merge 5 commits intolukeed:mainfrom
hi-ogawa:fix-158-content-encoding-only-for-accept-encoding

Conversation

@hi-ogawa
Copy link

@hi-ogawa hi-ogawa commented Aug 13, 2024

Content-Encoding should be used only when sirv is serving pre-compressed files (e.g. request: test.csv --> response: test.csv.gz), but it should be avoided when users are requesting a compressed file directly (e.g. test.csv.gz).

Citing from https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding

If the original media is encoded in some way (e.g. a zip file) then this information would not be included in the Content-Encoding header.


The summary of changes in this PR is:

  • replace extns: string with extns: { ext: string, encoded: boolean }[],
  • when matching a file with viaLocal or viaCache, it also returns { name: string, encoded: boolean }
  • move Content-Type and Content-Encoding handling from toHeaders to send since it now requires name and encoded to decide these two headers.

Diff looks a little involved, but I hope this is clear and correct. I would appreciate a review. Thanks!

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.

Downloading gzipped files in browsers

1 participant