Skip to content

Fix: Prevent Content-Type from being set to literal 'false' string#7043

Closed
realMelTuc wants to merge 1 commit intoexpressjs:masterfrom
realMelTuc:fix-content-type-false
Closed

Fix: Prevent Content-Type from being set to literal 'false' string#7043
realMelTuc wants to merge 1 commit intoexpressjs:masterfrom
realMelTuc:fix-content-type-false

Conversation

@realMelTuc
Copy link

When mime.contentType() returns false for unrecognized types, res.set() now preserves the original value instead of setting the header to the literal string 'false'.

Bug Description

Previously, when calling res.set('Content-Type', 'some-custom-type') with an unrecognized type, mime.contentType() would return false, and the header would be set to the literal string "false" instead of preserving the original value.

Root Cause

In lib/response.js, the res.set() function was directly assigning the result of mime.contentType(value) to the value variable without checking if it returned false.

Fix

Modified the Content-Type handling in res.set() to only update the value if mime.contentType() returns a non-false value, preserving the original value otherwise.

Test Added

Added a test case in test/res.set.js to verify that unrecognized Content-Type values are preserved correctly.

Fixes: Express issue #7034

When mime.contentType() returns false for unrecognized types, res.set()
now preserves the original value instead of setting the header to the
literal string 'false'.

Fixes: Express issue expressjs#7034
@krzysdz
Copy link
Contributor

krzysdz commented Feb 20, 2026

Duplicate of #7035

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

2 participants