diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index bc57cd067507f7..ebb339785d0b0c 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -552,7 +552,14 @@ function processHeader(self, state, key, value, validate) { // https://www.rfc-editor.org/rfc/rfc6266#section-4.3 // Refs: https://github.com/nodejs/node/pull/46528 if (isContentDispositionField(key) && self._contentLength) { - value = Buffer.from(value, 'latin1'); + // The value could be an array here + if (ArrayIsArray(value)) { + for (let i = 0; i < value.length; i++) { + value[i] = Buffer.from(value[i], 'latin1'); + } + } else { + value = Buffer.from(value, 'latin1'); + } } if (ArrayIsArray(value)) { diff --git a/test/parallel/test-http-server-non-utf8-header.js b/test/parallel/test-http-server-non-utf8-header.js index 331965ae38d0f8..8ce82ac4cada04 100644 --- a/test/parallel/test-http-server-non-utf8-header.js +++ b/test/parallel/test-http-server-non-utf8-header.js @@ -26,6 +26,27 @@ const nonUtf8ToLatin1 = Buffer.from(nonUtf8Header).toString('latin1'); })); } +{ + // Test multi-value header + const server = http.createServer(common.mustCall((req, res) => { + res.writeHead(200, [ + 'content-disposition', + [Buffer.from(nonUtf8Header).toString('binary')], + ]); + res.end('hello'); + })); + + server.listen(0, common.mustCall(() => { + http.get({ port: server.address().port }, (res) => { + assert.strictEqual(res.statusCode, 200); + assert.strictEqual(res.headers['content-disposition'], nonUtf8ToLatin1); + res.resume().on('end', common.mustCall(() => { + server.close(); + })); + }); + })); +} + { const server = http.createServer(common.mustCall((req, res) => { res.writeHead(200, [