Skip to content
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

Set the correct content type for gzipped files with the .gz ext #51

Conversation

dannyfallon
Copy link
Contributor

Using the gzip plugin it's possible to specify a keep option
which will maintain both the original uncompressed file and save
the gzipped version with a .gz suffix. Amazon S3 does not detect
content type or encoding so this is all managed in this plugin via
the mime package. The default mime type is application/octet-stream
which is exactly what is detected for a .gz files. Uploading
.js.gz and .css.gz files without their correct content types
blows up some browsers with syntax errors (e.g. Safari)

This PR makes the uploader a little smarter. If we detect a file is
gzipped and has a .gz extension we strip the extension and look for
the non-gzipped file in the file path list. If it's found, we'll do
a mime lookup for the non-gzipped file and use that content type
and encoding instead. If a non-gzipped counterpart isn't found we
will still upload the gzipped file as an application/octet-stream
so this shouldn't break any valid gzip assets that aren't compressed
as part of the gzip plugin in the pipeline.

Using the gzip plugin it's possible to specify a `keep` option
which will maintain both the original uncompressed file and save
the gzipped version with a `.gz` suffix. Amazon S3 does not detect
content type or encoding so this is all managed in this plugin via
the mime package. The default mime type is `application/octet-stream`
which is exactly what is detected for a `.gz` files. Uploading
`.js.gz` and `.css.gz` files without their correct content types
blows up some browsers with syntax errors (e.g. Safari)

This PR makes the uploader a little smarter. If we detect a file is
gzipped and has a `.gz` extension we strip the extension and look for
the non-gzipped file in the file path list. If it's found, we'll do
a mime lookup for the non-gzipped file and use _that_ content type
and encoding instead. If a non-gzipped counterpart isn't found we
will still upload the gzipped file as an `application/octet-stream`
so this shouldn't break any valid gzip assets that aren't compressed
as part of the gzip plugin in the pipeline.
@ghedamat
Copy link
Contributor

ghedamat commented Mar 8, 2016

thanks @dannyfallon for this!

LGTM at first pass but would love @achambers to confirm :)

@lukemelia lukemelia merged commit fb4efd3 into ember-cli-deploy:master Mar 28, 2016
@lukemelia
Copy link
Contributor

Thanks @dannyfallon!

@dannyfallon dannyfallon deleted the use-correct-contenttype-for-gzip-files branch August 25, 2017 13:43
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.

3 participants