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

Add content encoding to ContentType for text files #11

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ module.exports = CoreObject.extend({
var basePath = path.join(cwd, filePath);
var data = fs.readFileSync(basePath);
var contentType = mime.lookup(basePath);
var encoding = mime.charsets.lookup(contentType);
var key = path.join(prefix, filePath);
var isGzipped = gzippedFilePaths.indexOf(filePath) !== -1;

if (encoding) {
contentType += '; charset=';
contentType += encoding.toLowerCase();
}

var params = {
Bucket: bucket,
ACL: acl,
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/dist/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body: {}
8 changes: 4 additions & 4 deletions tests/unit/lib/s3-nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('s3', function() {
};

var options = {
filePaths: ['app.js'],
filePaths: ['app.css'],
cwd: process.cwd() + '/tests/fixtures/dist',
prefix: 'js-app',
bucket: 'some-bucket'
Expand All @@ -105,9 +105,9 @@ describe('s3', function() {
.then(function() {
assert.equal(s3Params.Bucket, 'some-bucket');
assert.equal(s3Params.ACL, 'public-read');
assert.equal(s3Params.Body.toString(), 'some content here\n');
assert.equal(s3Params.ContentType, 'application/javascript');
assert.equal(s3Params.Key, 'js-app/app.js');
assert.equal(s3Params.Body.toString(), 'body: {}\n');
assert.equal(s3Params.ContentType, 'text/css; charset=utf-8');
assert.equal(s3Params.Key, 'js-app/app.css');
assert.equal(s3Params.CacheControl, 'max-age=63072000, public');
assert.deepEqual(s3Params.Expires, new Date('2030'));
});
Expand Down