Skip to content

Commit 0d3809c

Browse files
committed
fix: throw error when Content-Type is invalid
when you call res.set('Content-Type', value) with something thats not a real MIME type, mime.contentType() returns false and that false was getting coerced to the string "false" and set as the header. now it throws a TypeError instead. fixes #7034
1 parent 9c85a25 commit 0d3809c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/response.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,11 @@ res.header = function header(field, val) {
673673
if (Array.isArray(value)) {
674674
throw new TypeError('Content-Type cannot be set to an Array');
675675
}
676-
value = mime.contentType(value)
676+
var contentType = mime.contentType(value);
677+
if (contentType === false) {
678+
throw new TypeError('invalid content type');
679+
}
680+
value = contentType;
677681
}
678682

679683
this.setHeader(field, value);

0 commit comments

Comments
 (0)