Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parseHeaders): util.parseHeaders handle correctly array of buffer… #2398

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/util.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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