Skip to content

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

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

fix: prevent res.set('Content-Type') from setting header to 'false'#7039
apoorvdarshan wants to merge 1 commit intoexpressjs:masterfrom
apoorvdarshan:fix/res-set-content-type-false

Conversation

@apoorvdarshan
Copy link

@apoorvdarshan apoorvdarshan commented Feb 18, 2026

Summary

  • When mime.contentType() cannot resolve a shorthand value (e.g., 'custom-type'), it returns false, which was silently set as the literal Content-Type header string "false"
  • Fall back to the original value instead, consistent with how res.type() already handles this case
  • Added tests for unknown Content-Type shorthands and valid full MIME types

Fixes #7034

Test plan

  • res.set('Content-Type', 'custom-type') preserves the original value instead of setting "false"
  • res.set('Content-Type', 'application/x-custom') works correctly with full MIME types
  • All existing tests continue to pass

When mime.contentType() cannot resolve a shorthand value, it returns
false, which was silently set as the Content-Type header. Fall back to
the original value instead.

Fixes expressjs#7034
@krzysdz
Copy link
Contributor

krzysdz commented Feb 18, 2026

Duplicate of #7035

@krzysdz krzysdz closed this Feb 18, 2026
@krzysdz krzysdz marked this as a duplicate of #7035 Feb 18, 2026
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

Comments