-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Downloading gzipped files in browsers #158
Comments
When loading a file that ends in `.gz`, `sirv` will set the `Content-Encoding` header to `gzip` which means browsers will unzip the content before handing it back to `fetch` or `XMLHttpRequest`. This PR adds a workaround to the asset server that sets the header to a garbage value if a file ending in `.gz` has been requested. It's necessary to use a garbage value because `sirv` will only set the header if it's not been set already, so we can't simply delete it. Refs: lukeed/sirv#158 Refs: ipfs/aegir#1462
When loading a file that ends in `.gz`, `sirv` will set the `Content-Encoding` header to `gzip` which means browsers will unzip the content before handing it back to `fetch` or `XMLHttpRequest`. This PR adds a workaround to the asset server that sets the header to a garbage value if a file ending in `.gz` has been requested. It's necessary to use a garbage value because `sirv` will only set the header if it's not been set already, so we can't simply delete it. Refs: lukeed/sirv#158 Refs: ipfs/aegir#1462
@lukeed would you accept a PR that added a |
Hi there, thanks for the report Agree that this should be fixed, however don't think adding a new config option is the solution here. I'll have a window today where I can put together what I have in mind |
@achingbrain Can you do me a favor & see if the following change works for you? // circa L112
-- if (enc) headers['Content-Encoding'] = enc;
++ if (enc && ctype) headers['Content-Encoding'] = enc; |
Thanks for taking a look. That works, but only because mrmime doesn't currently map |
If you try to download (for example) a
.tar.gz
viasirv
in a browser, because the file name ends in.gz
thetoHeaders
function setsContent-Encoding
to"gzip"
.This makes browsers ungzip the file before making the bytes available to the user.
If the intention was to download a
.tar.gz
file things break because they actually get back the equivalent of a.tar
file.The text was updated successfully, but these errors were encountered: