diff --git a/lib/dispatcher/client-h2.js b/lib/dispatcher/client-h2.js index 14e51db9949..661d857bee1 100644 --- a/lib/dispatcher/client-h2.js +++ b/lib/dispatcher/client-h2.js @@ -295,11 +295,13 @@ function writeH2 (client, request) { if (Array.isArray(val)) { for (let i = 0; i < val.length; i++) { if (headers[key]) { - headers[key] += `,${val[i]}` + headers[key] += `, ${val[i]}` } else { headers[key] = val[i] } } + } else if (headers[key]) { + headers[key] += `, ${val}` } else { headers[key] = val } diff --git a/test/http2.js b/test/http2.js index fb16e2d4a15..a370af1b60f 100644 --- a/test/http2.js +++ b/test/http2.js @@ -125,8 +125,9 @@ test('Should support H2 connection (headers as array)', async t => { const server = createSecureServer(pem) server.on('stream', (stream, headers) => { - t.strictEqual(headers['x-my-header'], 'foo') - t.strictEqual(headers['x-my-drink'], 'coffee,tea') + t.strictEqual(headers['x-my-header'], 'foo, bar') + t.strictEqual(headers['x-my-drink'], 'coffee, tea, water') + t.strictEqual(headers['x-other'], 'value') t.strictEqual(headers[':method'], 'GET') stream.respond({ 'content-type': 'text/plain; charset=utf-8', @@ -146,14 +147,20 @@ test('Should support H2 connection (headers as array)', async t => { allowH2: true }) - t = tspl(t, { plan: 7 }) + t = tspl(t, { plan: 8 }) after(() => server.close()) after(() => client.close()) const response = await client.request({ path: '/', method: 'GET', - headers: ['x-my-header', 'foo', 'x-my-drink', ['coffee', 'tea']] + headers: [ + 'x-my-header', 'foo', + 'x-my-drink', ['coffee', 'tea'], + 'x-my-drink', 'water', + 'X-My-Header', 'bar', + 'x-other', 'value' + ] }) response.body.on('data', chunk => {