Skip to content

Commit

Permalink
Work around Content-type being empty in S3
Browse files Browse the repository at this point in the history
  • Loading branch information
jaens committed Nov 6, 2021
1 parent 928bff6 commit 16e14f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/src/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ const PDF_MIME_TYPES = new Set([
"application/acrobat",
"applications/vnd.pdf",
]);
const BINARY_MIME_TYPES = new Set(["application/octet-stream", "application/force-download", "binary/octet-stream"]);
const BINARY_MIME_TYPES = new Set([
"application/octet-stream",
"application/force-download",
"binary/octet-stream",
// S3 buckets might have files without Content-type set
"",
]);
const HEADER_CONTENT_DISPOSITION = "Content-Disposition";
const HEADER_CONTENT_TYPE = "Content-Type";

Expand Down
14 changes: 13 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

import * as headers from "../app/src/headers.js";
import { deepStrictEqual } from "assert";
import * as headers from "../app/src/headers.js";

describe("Handle Headers", () => {
testHandleHeaders("Empty", "", [], false);
Expand Down Expand Up @@ -161,6 +161,18 @@ describe("Handle Headers", () => {
["Content-Type", "application/pdf"],
]
);
testHandleHeaders(
"Amazon S3 without content type with PDF file name(s)",
"http://some-bucket.s3.us-east-1.amazonaws.com/12345.pdf?response-content-disposition=attachment",
[
["Content-Disposition", "attachment"],
["Content-Type", ""],
],
[
["Content-Disposition", "inline"],
["Content-Type", "application/pdf"],
]
);
});

/* Helper Functions */
Expand Down

0 comments on commit 16e14f7

Please sign in to comment.