Skip to content

Commit 775174f

Browse files
committed
Merge pull request #11 from strange-studios/add-encoding-to-content-type
Add content encoding to ContentType for text files
2 parents 1932db5 + 5d3d919 commit 775174f

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/s3.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,15 @@ module.exports = CoreObject.extend({
8080
var basePath = path.join(cwd, filePath);
8181
var data = fs.readFileSync(basePath);
8282
var contentType = mime.lookup(basePath);
83+
var encoding = mime.charsets.lookup(contentType);
8384
var key = path.join(prefix, filePath);
8485
var isGzipped = gzippedFilePaths.indexOf(filePath) !== -1;
8586

87+
if (encoding) {
88+
contentType += '; charset=';
89+
contentType += encoding.toLowerCase();
90+
}
91+
8692
var params = {
8793
Bucket: bucket,
8894
ACL: acl,

tests/fixtures/dist/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body: {}

tests/unit/lib/s3-nodetest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('s3', function() {
9393
};
9494

9595
var options = {
96-
filePaths: ['app.js'],
96+
filePaths: ['app.css'],
9797
cwd: process.cwd() + '/tests/fixtures/dist',
9898
prefix: 'js-app',
9999
bucket: 'some-bucket'
@@ -105,9 +105,9 @@ describe('s3', function() {
105105
.then(function() {
106106
assert.equal(s3Params.Bucket, 'some-bucket');
107107
assert.equal(s3Params.ACL, 'public-read');
108-
assert.equal(s3Params.Body.toString(), 'some content here\n');
109-
assert.equal(s3Params.ContentType, 'application/javascript');
110-
assert.equal(s3Params.Key, 'js-app/app.js');
108+
assert.equal(s3Params.Body.toString(), 'body: {}\n');
109+
assert.equal(s3Params.ContentType, 'text/css; charset=utf-8');
110+
assert.equal(s3Params.Key, 'js-app/app.css');
111111
assert.equal(s3Params.CacheControl, 'max-age=63072000, public');
112112
assert.deepEqual(s3Params.Expires, new Date('2030'));
113113
});

0 commit comments

Comments
 (0)