From 2333461e237e44bdfcdc686c269b4408374b226e Mon Sep 17 00:00:00 2001 From: simonihmig Date: Wed, 9 Sep 2020 21:36:02 +0200 Subject: [PATCH] Add brotli support Add support for brotli-compressed index.html, as `ember-cli-deploy-s3` already supports that (see https://github.com/ember-cli-deploy/ember-cli-deploy-s3/pull/104) --- lib/s3.js | 30 ++++++++++++++++++------------ tests/unit/lib/s3-test.js | 10 ++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/s3.js b/lib/s3.js index 0da6edd..4fe3420 100644 --- a/lib/s3.js +++ b/lib/s3.js @@ -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, @@ -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); diff --git a/tests/unit/lib/s3-test.js b/tests/unit/lib/s3-test.js index b8af155..269ee86 100644 --- a/tests/unit/lib/s3-test.js +++ b/tests/unit/lib/s3-test.js @@ -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';