Skip to content

Commit

Permalink
fix(infra): correctly download .tar.gz files
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Sep 6, 2022
1 parent 85386fc commit 197866d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion infra/data/lambda-at-edge/OriginRequest.lambda.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable prefer-destructuring */
/* eslint-disable prefer-destructuring,sonarjs/no-collapsible-if,unicorn/no-lonely-if */
// Implements rewrite of non-compressed to .gz URLs using AWS
// Lambda@Edge. This is useful if you have precompressed your files.
//
Expand Down
18 changes: 7 additions & 11 deletions infra/data/lambda-at-edge/OriginResponse.lambda.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-collapsible-if,unicorn/no-lonely-if */
// Workaround! Fixes HTTP headers for serving broken S3 uploads:
// 'Cache-Control': 'no-cache',
// 'Content-Encoding': 'gzip',
Expand All @@ -6,22 +7,17 @@
// event of a Cloudfront distribution

const NEW_HEADERS_FIX_CACHE = {
'Cache-Control': 'no-cache',
'cache-control': 'no-cache',
}

const NEW_HEADERS_FIX_COMPRESSION = {
'Content-Encoding': 'gzip',
'content-encoding': 'gzip',
}

const ARCHIVE_EXTS = ['.7z', '.br', '.bz2', '.gz', '.lzma', '.xz', '.zip', '.zst']
const ARCHIVE_EXTS = ['.7z', '.bz2', '.lzma', '.tar.gz', '.xz', '.zip', '.zst']

function addHeaders(headersObject) {
return Object.fromEntries(
Object.entries(headersObject).map(([header, value]) => [header.toLowerCase(), [{
key: header,
value
}]]),
)
return Object.fromEntries(Object.entries(headersObject).map(([header, value]) => [header.toLowerCase(), [{ value }]]))
}

function getHeader(headers, headerName) {
Expand All @@ -44,10 +40,10 @@ function modifyHeaders({ request, response }) {
let newHeaders = addHeaders(NEW_HEADERS_FIX_CACHE)

if (ARCHIVE_EXTS.every((ext) => !request.uri.endsWith(ext))) {
if(acceptsEncoding(request.headers, 'gzip')) {
if (acceptsEncoding(request.headers, 'gzip')) {
newHeaders = {
...newHeaders,
...addHeaders(NEW_HEADERS_FIX_COMPRESSION)
...addHeaders(NEW_HEADERS_FIX_COMPRESSION),
}
}
}
Expand Down

0 comments on commit 197866d

Please sign in to comment.