Skip to content

Commit

Permalink
Add brotli support
Browse files Browse the repository at this point in the history
Add support for brotli-compressed index.html, as `ember-cli-deploy-s3` already supports that (see ember-cli-deploy/ember-cli-deploy-s3#104)
  • Loading branch information
simonihmig committed Sep 9, 2020
1 parent 135311c commit 2333461
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ module.exports = CoreObject.extend({
},

upload: function(options) {
var client = this._client;
var plugin = this._plugin;
var bucket = options.bucket;
var acl = options.acl;
var cacheControl = options.cacheControl;
var allowOverwrite = options.allowOverwrite;
var key = options.filePattern + ":" + options.revisionKey;
var revisionKey = joinUriSegments(options.prefix, key);
var putObject = RSVP.denodeify(client.putObject.bind(client));
var gzippedFilePaths = options.gzippedFilePaths || [];
var isGzipped = gzippedFilePaths.indexOf(options.filePattern) !== -1;
var serverSideEncryption = options.serverSideEncryption;
var client = this._client;
var plugin = this._plugin;
var bucket = options.bucket;
var acl = options.acl;
var cacheControl = options.cacheControl;
var allowOverwrite = options.allowOverwrite;
var key = options.filePattern + ":" + options.revisionKey;
var revisionKey = joinUriSegments(options.prefix, key);
var putObject = RSVP.denodeify(client.putObject.bind(client));
var gzippedFilePaths = options.gzippedFilePaths || [];
var brotliCompressedFilePaths = options.brotliCompressedFilePaths || [];
var isGzipped = gzippedFilePaths.indexOf(options.filePattern) !== -1;
var isBrotliCompressed = brotliCompressedFilePaths.indexOf(options.filePattern) !== -1;
var serverSideEncryption = options.serverSideEncryption;

var params = {
Bucket: bucket,
Expand All @@ -77,6 +79,10 @@ module.exports = CoreObject.extend({
params.ContentEncoding = 'gzip';
}

if (isBrotliCompressed) {
params.ContentEncoding = 'br';
}

return this.fetchRevisions(options)
.then(function(revisions) {
var found = revisions.map(function(element) { return element.revision; }).indexOf(options.revisionKey);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/lib/s3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ describe('s3', function() {
});
});

it('sets the Content-Encoding header to br when the index file is brotli compressed', function() {
options.brotliCompressedFilePaths = [filePattern];
var promise = subject.upload(options);

return assert.isFulfilled(promise)
.then(function() {
assert.equal(s3Params.ContentEncoding, 'br', 'contentEncoding is set to br');
});
});

it('allows `prefix` option to be passed to customize upload-path', function() {
var prefix = 'my-app';

Expand Down

0 comments on commit 2333461

Please sign in to comment.