From ee4332244028f884b2b97a672d33791b09dfc993 Mon Sep 17 00:00:00 2001 From: linhongkuan Date: Wed, 24 Jun 2026 21:56:58 +0800 Subject: [PATCH] fix(res.append): preserve empty header values --- lib/response.js | 2 +- test/res.append.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index b4755a5c060..268f8f7980c 100644 --- a/lib/response.js +++ b/lib/response.js @@ -633,7 +633,7 @@ res.append = function append(field, val) { var prev = this.get(field); var value = val; - if (prev) { + if (prev !== undefined) { // concat the new and prev vals value = Array.isArray(prev) ? prev.concat(val) : Array.isArray(val) ? [prev].concat(val) diff --git a/test/res.append.js b/test/res.append.js index 2dd17a3a1fb..93a52d97ba2 100644 --- a/test/res.append.js +++ b/test/res.append.js @@ -82,6 +82,21 @@ describe('res', function () { .end(done) }) + it('should preserve an existing empty header value', function (done) { + var app = express() + + app.use(function (req, res) { + res.set('Warning', '') + res.append('Warning', '199 Miscellaneous warning') + res.end(JSON.stringify(res.get('Warning'))) + }) + + request(app) + .get('/') + .expect(200, '["","199 Miscellaneous warning"]') + .end(done) + }) + it('should work together with res.cookie', function (done) { var app = express()