Repository navigation
fix(node): add the charset to a content type the app sets - #18391
Merged
kamilmysliwiec merged 1 commit intoNov 4, 2026
Merged
Conversation
NodeResponse.set(), header(), type() and NodeAdapter.setHeader() (the @Header() path) sent a Content-Type as it was given. Express runs it through mime-types, so text/html is sent as text/html; charset=utf-8. An array Content-Type now throws a TypeError, as it does in Express.
3 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The
NodeAdaptersends aContent-Typeas the app gives it. Express runs it throughmime-types, so it adds; charset=utf-8totext/*,application/jsonand the other types that have a charset.Content-Typesenttext/html; charset=utf-8text/htmlA browser then guesses the charset, and non-ASCII text can show up broken. The same happens with
res.set(),res.header()andres.type('text/html')on the node response.res.set('Content-Type', [...])is accepted, but Express throws aTypeError.Issue Number: N/A
What is the new behavior?
NodeResponse.set()(and soheader(), andtype()) andNodeAdapter.setHeader()(the@Header()path, as in theExpressAdapter) run aContent-Typethrough the samemime-typeslookup thattype()already used:Content-Typesenttext/html; charset=utf-8text/html; charset=utf-8text/html; charset=latin1.application/vnd.api+json,image/png.|| valuefallback), so it is never turned intofalse.Content-TypethrowsTypeError('Content-Type cannot be set to an Array'), as Express does.Tests:
node-request.spec.ts(set()/header()andtype()),node-adapter.spec.ts(setHeader()thenreply()), and a@Header('Content-Type', 'text/html')route inintegration/http-adaptersthat runs for express and node. All new cases fail on master and pass with the fix. One oldsend()test expectedtext/htmlback forset('Content-Type', 'text/html'); it now expects the charset, as Express sends it.Not in this PR: Express
res.send(string)also adds the charset to a preset type that has none in mime-db (res.set('Content-Type', 'application/vnd.api+json').send('...')givesapplication/vnd.api+json; charset=utf-8). The node adapter keeps the type as it is. I left it out to keep this change small. I can send it as a follow-up if you want it.Does this PR introduce a breaking change?
@nestjs/platform-nodeis new in 12.3. An app that setstext/htmlby hand now gets the charset, which is what Express sends too.Other information
Found by comparing the
NodeAdapterwith Express 5.3 for the same@Header()route.