Skip to content

Commit fb4efd3

Browse files
committed
Merge pull request #51 from dannyfallon/use-correct-contenttype-for-gzip-files
Set the correct content type for gzipped files with the .gz ext
2 parents 17c922f + 5a5abdd commit fb4efd3

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/s3.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ module.exports = CoreObject.extend({
9191
var key = prefix === '' ? filePath : [prefix, filePath].join('/');
9292
var isGzipped = gzippedFilePaths.indexOf(filePath) !== -1;
9393

94+
if (isGzipped && path.extname(basePath) === '.gz') {
95+
var basePathUncompressed = path.basename(basePath, '.gz');
96+
if (filePaths.indexOf(basePathUncompressed) !== -1) {
97+
contentType = mime.lookup(basePathUncompressed);
98+
encoding = mime.charsets.lookup(contentType);
99+
}
100+
}
101+
94102
if (encoding) {
95103
contentType += '; charset=';
96104
contentType += encoding.toLowerCase();

tests/fixtures/dist/app.css.gz

37 Bytes
Binary file not shown.

tests/unit/lib/s3-nodetest.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,35 @@ describe('s3', function() {
110110
assert.equal(s3Params.ContentType, 'text/css; charset=utf-8');
111111
assert.equal(s3Params.Key, 'js-app/app.css');
112112
assert.equal(s3Params.CacheControl, 'max-age=63072000, public');
113+
assert.isUndefined(s3Params.ContentEncoding);
114+
assert.deepEqual(s3Params.Expires, new Date('2030'));
115+
});
116+
});
117+
118+
it('sends the correct content type params for gzipped files with .gz extension', function() {
119+
var s3Params;
120+
s3Client.putObject = function(params, cb) {
121+
s3Params = params;
122+
cb();
123+
};
124+
125+
var options = {
126+
filePaths: ['app.css', 'app.css.gz'],
127+
gzippedFilePaths: ['app.css.gz'],
128+
cwd: process.cwd() + '/tests/fixtures/dist',
129+
prefix: 'js-app',
130+
acl: 'public-read',
131+
bucket: 'some-bucket'
132+
};
133+
134+
var promises = subject.upload(options);
135+
136+
return assert.isFulfilled(promises)
137+
.then(function() {
138+
assert.equal(s3Params.ContentType, 'text/css; charset=utf-8');
139+
assert.equal(s3Params.Key, 'js-app/app.css.gz');
140+
assert.equal(s3Params.CacheControl, 'max-age=63072000, public');
141+
assert.equal(s3Params.ContentEncoding, 'gzip');
113142
assert.deepEqual(s3Params.Expires, new Date('2030'));
114143
});
115144
});

0 commit comments

Comments
 (0)