Skip to content

fix: res.set('Content-Type') silently sets header to literal string#7111

Closed
JiwaniZakir wants to merge 1 commit intoexpressjs:masterfrom
JiwaniZakir:fix/issue-7034
Closed

fix: res.set('Content-Type') silently sets header to literal string#7111
JiwaniZakir wants to merge 1 commit intoexpressjs:masterfrom
JiwaniZakir:fix/issue-7034

Conversation

@JiwaniZakir
Copy link

Fixes #7034

When res.set('Content-Type', value) was called with an unrecognized MIME type, mime.contentType() returned false, and that false value was passed directly to this.setHeader(), resulting in the literal string 'false' being set as the Content-Type header. The fix in lib/response.js changes the assignment in res.header to mime.contentType(value) || value, falling back to the original value when mime.contentType() returns a falsy result. This preserves the existing behavior for recognized types while allowing unrecognized but valid Content-Type strings (e.g. custom or vendor types) to pass through unchanged. Verified against the reported reproduction case where res.set('Content-Type', 'application/vnd.custom') previously set the header to 'false'.

@krzysdz
Copy link
Contributor

krzysdz commented Mar 17, 2026

Duplicate of #7035

@krzysdz krzysdz marked this as a duplicate of #7035 Mar 17, 2026
@krzysdz krzysdz closed this Mar 17, 2026
@krzysdz
Copy link
Contributor

krzysdz commented Mar 17, 2026

Verified against the reported reproduction case where res.set('Content-Type', 'application/vnd.custom') previously set the header to 'false'.

This works even without this change and the issue (and my comment) explicitly mention that the problem occurs when the "type" does not contain a / character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

res.set('Content-Type') silently sets header to literal string 'false' for unknown types

2 participants