diff --git a/lib/upload.js b/lib/upload.js index 9385e15..ba473e6 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -62,7 +62,7 @@ function uploadFile(aws, bucketName, filePath, fileKey, headers, sse) { Bucket: bucketName, Key: fileKey, Body: fileBuffer, - ContentType: mime.lookup(filePath) + ...getMimeTypeAndContentEncoding(filePath) }; if (sse) { @@ -180,4 +180,24 @@ function groupFilesByOrder(files, orderSpec) { return [unmatchedFiles].concat(matchedFiles); } +const ContentEncodingMap = { + gz: 'gzip', + br: 'br' +}; + +function getMimeTypeAndContentEncoding(filePath) { + const match = /(.+\..+)\.(gz|br)$/.exec(filePath); + + if (match) { + const [fullMatch, strippedFilePath, encodingFileEnding] = match; + + return { + ContentType: mime.lookup(strippedFilePath), + ContentEncoding: ContentEncodingMap[encodingFileEnding] + }; + } + + return { ContentType: mime.lookup(filePath) }; +} + module.exports = uploadDirectory;