Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ res.header = function header(field, val) {
if (Array.isArray(value)) {
throw new TypeError('Content-Type cannot be set to an Array');
}
value = mime.contentType(value)
value = mime.contentType(value) || value
}

this.setHeader(field, value);
Expand Down
14 changes: 14 additions & 0 deletions test/res.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ describe('res', function(){
.expect('X-Number', '123')
.expect(200, 'string', done);
})

it('should preserve Content-Type value when mime lookup fails', function (done) {
var app = express();

app.use(function (req, res) {
res.set('Content-Type', 'custom-type');
res.end();
});

request(app)
.get('/')
.expect('Content-Type', 'custom-type')
.expect(200, done);
})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
})
})
it('should preserve Content-Type value when mime lookup fails even has slash', function (done) {
var app = express();
app.use(function (req, res) {
res.set('Content-Type', 'custom-type/subtype');
res.end();
});
request(app)
.get('/')
.expect('Content-Type', 'custom-type/subtype')
.expect(200, done);
})

Since MIME types are closely related to slash based formats, adding a test case that includes a slash helps catch potential production issues before release.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the string passed to mime.contentType() contains a /, then it is treated as a mime type and returned as is (ref).

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, that makes my additional test is unnecessary, thank you.

})

describe('.set(field, values)', function(){
Expand Down