Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,6 @@ function _asyncReadfile (filename) {
* @return {string} A content type string
*/
function getContentType (headers) {
const headerValue = headers.get ? headers.get('content-type') : headers['content-type']

// Default content type as stated by RFC 822

@RubenVerborgh RubenVerborgh Jul 8, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC 822 doesn't even contain the string "text/plain" and predates HTTP, so completely bogus.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. For completeness' sake, RFC 1521 (since obsoleted) would have been the appropriate reference --

When a mail reader encounters mail with an unknown Content-type
value, it should generally treat it as equivalent to
"application/octet-stream", as described later in this document.

if (!headerValue) {
return 'text/plain'
}

// Remove charset suffix
return headerValue.split(';')[0]
const value = headers.get ? headers.get('content-type') : headers['content-type']
return value ? value.replace(/;.*/, '') : 'application/octet-stream'
}
8 changes: 4 additions & 4 deletions test/unit/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ describe('Utility functions', function () {

describe('getContentType()', () => {
describe('for Express headers', () => {
it('should default to text/plain', () => {
assert.equal(utils.getContentType({}), 'text/plain')
it('should default to application/octet-stream', () => {
assert.equal(utils.getContentType({}), 'application/octet-stream')
})

it('should get a basic content type', () => {
Expand All @@ -87,9 +87,9 @@ describe('Utility functions', function () {
})

describe('for Fetch API headers', () => {
it('should default to text/plain', () => {
it('should default to application/octet-stream', () => {
// eslint-disable-next-line no-undef
assert.equal(utils.getContentType(new Headers({})), 'text/plain')
assert.equal(utils.getContentType(new Headers({})), 'application/octet-stream')
})

it('should get a basic content type', () => {
Expand Down