Skip to content

Commit

Permalink
Support binary/octet-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
MorbZ committed Mar 5, 2019
1 parent aad66df commit 2012edd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "No PDF Download",
"description": "Opens all PDF files directly in the browser.",
"version": "1.0.4",
"version": "1.0.5",

"permissions": [
"webRequest",
Expand Down
6 changes: 5 additions & 1 deletion app/src/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const PDF_MIME_TYPES = [
'application/acrobat',
'applications/vnd.pdf',
];
const BINARY_MIME_TYPES = [
'application/octet-stream',
'binary/octet-stream',
];
const HEADER_CONTENT_DISPOSITION = 'Content-Disposition';
const HEADER_CONTENT_TYPE = 'Content-Type';

Expand All @@ -38,7 +42,7 @@ function isPdf(url, type, disposition) {
}

// Octet-streams may be PDFs, we have to check the extension
if(mimeType != 'application/octet-stream') {
if(!BINARY_MIME_TYPES.includes(mimeType)) {
return false;
}

Expand Down
8 changes: 8 additions & 0 deletions test/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ describe('Handle Headers', () => {
['Content-Type', 'application/pdf'],
['Content-Disposition', 'inline'],
]);

testHandleHeaders('Binary/Octet-stream with PDF file name(s)', 'http://test.com/02000', [
['Content-Disposition', 'attachment; filename="ABC_2019.pdf"; filename*=UTF-8\'\'ABC_2019.pdf'],
['Content-Type', 'binary/octet-stream'],
], [
['Content-Disposition', 'inline; filename="ABC_2019.pdf"; filename*=UTF-8\'\'ABC_2019.pdf'],
['Content-Type', 'application/pdf'],
]);
});

/* Helper Functions */
Expand Down

0 comments on commit 2012edd

Please sign in to comment.