diff --git a/lib/internal/http2/util.js b/lib/internal/http2/util.js index 2426a409cfc6cf..013642d40d1286 100644 --- a/lib/internal/http2/util.js +++ b/lib/internal/http2/util.js @@ -403,13 +403,14 @@ function mapToHeaders(map, if (typeof key === 'symbol' || value === undefined || !key) continue; key = String(key).toLowerCase(); - const isArray = Array.isArray(value); + let isArray = Array.isArray(value); if (isArray) { switch (value.length) { case 0: continue; case 1: value = String(value[0]); + isArray = false; break; default: if (kSingleValueHeaders.has(key)) diff --git a/test/parallel/test-http2-util-headers-list.js b/test/parallel/test-http2-util-headers-list.js index 1884a22894d280..f5e202538502eb 100644 --- a/test/parallel/test-http2-util-headers-list.js +++ b/test/parallel/test-http2-util-headers-list.js @@ -154,6 +154,18 @@ const { ); } +{ + // Arrays containing a single set-cookie value are handled correctly + // (https://github.com/nodejs/node/issues/16452) + const headers = { + 'set-cookie': 'foo=bar' + }; + assert.deepStrictEqual( + mapToHeaders(headers), + [ [ 'set-cookie', 'foo=bar', '' ].join('\0'), 1 ] + ); +} + // The following are not allowed to have multiple values [ HTTP2_HEADER_STATUS,