Skip to content

Commit 329913c

Browse files
aviu16claude
andcommitted
fix: throw error when Content-Type is invalid
When calling res.set('Content-Type', value) where value is not a valid MIME type (e.g., 'some-custom-type'), mime.contentType() returns false. Previously, this false value was coerced to the string "false" and set as the Content-Type header. This change throws a TypeError when mime.contentType() returns false, making the error explicit and easier to catch. This behavior aligns with the existing TypeError thrown for Array values. Fixes #7034 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 9c85a25 commit 329913c

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)