Skip to content

Commit bd24250

Browse files
authored
fix: Ensure conflicting flat headers in HTTP/2 are combined correctly (#4196)
1 parent 14e62db commit bd24250

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

lib/dispatcher/client-h2.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,13 @@ function writeH2 (client, request) {
295295
if (Array.isArray(val)) {
296296
for (let i = 0; i < val.length; i++) {
297297
if (headers[key]) {
298-
headers[key] += `,${val[i]}`
298+
headers[key] += `, ${val[i]}`
299299
} else {
300300
headers[key] = val[i]
301301
}
302302
}
303+
} else if (headers[key]) {
304+
headers[key] += `, ${val}`
303305
} else {
304306
headers[key] = val
305307
}

test/http2.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ test('Should support H2 connection (headers as array)', async t => {
125125
const server = createSecureServer(pem)
126126

127127
server.on('stream', (stream, headers) => {
128-
t.strictEqual(headers['x-my-header'], 'foo')
129-
t.strictEqual(headers['x-my-drink'], 'coffee,tea')
128+
t.strictEqual(headers['x-my-header'], 'foo, bar')
129+
t.strictEqual(headers['x-my-drink'], 'coffee, tea, water')
130+
t.strictEqual(headers['x-other'], 'value')
130131
t.strictEqual(headers[':method'], 'GET')
131132
stream.respond({
132133
'content-type': 'text/plain; charset=utf-8',
@@ -146,14 +147,20 @@ test('Should support H2 connection (headers as array)', async t => {
146147
allowH2: true
147148
})
148149

149-
t = tspl(t, { plan: 7 })
150+
t = tspl(t, { plan: 8 })
150151
after(() => server.close())
151152
after(() => client.close())
152153

153154
const response = await client.request({
154155
path: '/',
155156
method: 'GET',
156-
headers: ['x-my-header', 'foo', 'x-my-drink', ['coffee', 'tea']]
157+
headers: [
158+
'x-my-header', 'foo',
159+
'x-my-drink', ['coffee', 'tea'],
160+
'x-my-drink', 'water',
161+
'X-My-Header', 'bar',
162+
'x-other', 'value'
163+
]
157164
})
158165

159166
response.body.on('data', chunk => {

0 commit comments

Comments
 (0)