Skip to content

fix: remove implicit Content-Type magic in res.set (#7145)#7283

Open
luvsharma6342 wants to merge 1 commit into
expressjs:masterfrom
luvsharma6342:fix/remove-res-set-magic-7145
Open

fix: remove implicit Content-Type magic in res.set (#7145)#7283
luvsharma6342 wants to merge 1 commit into
expressjs:masterfrom
luvsharma6342:fix/remove-res-set-magic-7145

Conversation

@luvsharma6342

Copy link
Copy Markdown

What’s included in the PR

lib/response.js: removed the Content-Type “magic” from res.set (no implicit MIME lookup / no charset injection); updated JSDoc
test/res.set.js: added assertions for pass-through Content-Type
test/res.send.js: updated expectations for Buffer/Uint8Array cases that previously depended on the old res.set behavior
Tests I ran locally
npx mocha ... test/res.set.js (passing)
npx mocha ... test/res.send.js (passing)

@notadev99 notadev99 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behavior-breaking change — today res.set('Content-Type', 'text/plain') yields text/plain; charset=utf-8 and 'html' resolves to text/html; charset=utf-8; after this both pass through verbatim. A few things worth nailing down:

Release target. Which line is this aimed at? Dropping the implicit charset changes real responses, so it reads like major-version material rather than a patch.

Migration path / blast radius. The JSDoc now points to res.type() for charset and shorthand, which is the right pointer. Can you confirm the common res.send('...') path (no explicit Content-Type) still emits charset=utf-8? The two res.send test edits suggest the default may now drop charset as well, which would be a much wider change than just explicit res.set calls.

Compat note. Serving text/html with no charset lets a browser sniff the encoding. Modern browsers default to UTF-8 so this is mostly historical, but a line in the changelog/migration notes would help anyone relying on the implicit charset know to switch to res.type().

Coverage for the new pass-through behavior looks good.

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