From 35a61a35e1d17db4b961b4554f0e6896e5e0fca4 Mon Sep 17 00:00:00 2001 From: realMelTuc Date: Thu, 19 Feb 2026 20:02:04 -0500 Subject: [PATCH] Fix: Prevent Content-Type from being set to literal 'false' string 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 #7034 --- lib/response.js | 5 ++++- test/res.set.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index f965e539dd2..c8e7d3dabba 100644 --- a/lib/response.js +++ b/lib/response.js @@ -673,7 +673,10 @@ res.header = function header(field, val) { if (Array.isArray(value)) { throw new TypeError('Content-Type cannot be set to an Array'); } - value = mime.contentType(value) + var ct = mime.contentType(value) + if (ct !== false) { + value = ct + } } this.setHeader(field, value); diff --git a/test/res.set.js b/test/res.set.js index 04511c1c95f..22c9cfb5c62 100644 --- a/test/res.set.js +++ b/test/res.set.js @@ -87,6 +87,20 @@ describe('res', function(){ .get('/') .expect(500, /TypeError: Content-Type cannot be set to an Array/, done) }) + + it('should preserve the original value when mime.contentType returns false', function (done) { + var app = express() + + app.use(function (req, res) { + res.set('Content-Type', 'some-custom-type') + res.end() + }); + + request(app) + .get('/') + .expect('Content-Type', 'some-custom-type') + .expect(200, done) + }) }) describe('.set(object)', function(){