Skip to content

Commit

Permalink
fix(parseHeaders): util.parseHeaders handle correctly array of buffer…
Browse files Browse the repository at this point in the history
… as value
  • Loading branch information
mdoria12 committed Nov 3, 2023
1 parent 45b904c commit fb4f9fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/core/util.js
Expand Up @@ -228,7 +228,7 @@ function parseHeaders (headers, obj = {}) {

if (!val) {
if (Array.isArray(headers[i + 1])) {
obj[key] = headers[i + 1]
obj[key] = headers[i + 1].map(x => x.toString('utf8'))
} else {
obj[key] = headers[i + 1].toString('utf8')
}
Expand Down
6 changes: 5 additions & 1 deletion test/mock-agent.js
Expand Up @@ -2594,5 +2594,9 @@ test('MockAgent - headers should be array of strings', async (t) => {
method: 'GET'
})

t.equal(headers['set-cookie'].length, 3)
t.same(headers['set-cookie'], [
'foo=bar',
'bar=baz',
'baz=qux'
])
})
3 changes: 2 additions & 1 deletion test/util.js
Expand Up @@ -83,12 +83,13 @@ test('validateHandler', (t) => {
})

test('parseHeaders', (t) => {
t.plan(5)
t.plan(6)
t.same(util.parseHeaders(['key', 'value']), { key: 'value' })
t.same(util.parseHeaders([Buffer.from('key'), Buffer.from('value')]), { key: 'value' })
t.same(util.parseHeaders(['Key', 'Value']), { key: 'Value' })
t.same(util.parseHeaders(['Key', 'value', 'key', 'Value']), { key: ['value', 'Value'] })
t.same(util.parseHeaders(['key', ['value1', 'value2', 'value3']]), { key: ['value1', 'value2', 'value3'] })
t.same(util.parseHeaders([Buffer.from('key'), [Buffer.from('value1'), Buffer.from('value2'), Buffer.from('value3')]]), { key: ['value1', 'value2', 'value3'] })
})

test('parseRawHeaders', (t) => {
Expand Down

0 comments on commit fb4f9fc

Please sign in to comment.