Skip to content

fix(res.set): keep unknown Content-Type values instead of 'false'#7071

Closed
ericpan17 wants to merge 1 commit intoexpressjs:masterfrom
ericpan17:fix/content-type-false-fallback
Closed

fix(res.set): keep unknown Content-Type values instead of 'false'#7071
ericpan17 wants to merge 1 commit intoexpressjs:masterfrom
ericpan17:fix/content-type-false-fallback

Conversation

@ericpan17
Copy link

Summary

Fixes res.set('Content-Type', value) behavior when mime.contentType(value) cannot resolve a known type.

Currently, unresolved values can become the literal header Content-Type: false.
This change preserves the original input value instead.

Changes

  • In res.set content-type normalization branch:
    • from: value = mime.contentType(value)
    • to: value = mime.contentType(value) || value
  • Added regression test:
    • should keep unknown Content-Type values

Why

res.type() already uses this fallback strategy. This aligns res.set('Content-Type', ...) with that behavior and avoids invalid-looking header output.

Validation

  • Ran focused test file:
    • npx mocha --require test/support/env test/res.set.js
  • New test passes.

@krzysdz
Copy link
Contributor

krzysdz commented Mar 1, 2026

Duplicate of #7035

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

3 participants