Skip to content

fix(res): preserve original value when mime.contentType() returns false#7046

Closed
speedcoder430 wants to merge 1 commit intoexpressjs:masterfrom
speedcoder430:fix/res-set-content-type-false-7034
Closed

fix(res): preserve original value when mime.contentType() returns false#7046
speedcoder430 wants to merge 1 commit intoexpressjs:masterfrom
speedcoder430:fix/res-set-content-type-false-7034

Conversation

@speedcoder430
Copy link

fix: prevent res.set('Content-Type') from setting header to literal string 'false'

When calling res.set('Content-Type', value) with a value that mime.contentType() cannot resolve (e.g., 'some-custom-type', it returns false. This false was passed directly to setHeader(), which coerced it to the string "false" — resulting in Content-Type: false in the response headers.

This change falls back to the original value when mime.contentType() returns false, consistent with how res.type() already handles this case.

Changes:

  • response.js : mime.contentType(value)mime.contentType(value) || value
  • res.set.js : Added test to verify the original value is preserved for unrecognized types

Fixes #7034

@krzysdz
Copy link
Contributor

krzysdz commented Feb 21, 2026

Duplicate of #7035

@krzysdz krzysdz marked this as a duplicate of #7035 Feb 21, 2026
@krzysdz krzysdz closed this Feb 21, 2026
@speedcoder430 speedcoder430 deleted the fix/res-set-content-type-false-7034 branch February 23, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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