Skip to content

Commit

Permalink
Allow string[] as Record value on HeadersInit (nodejs#1244)
Browse files Browse the repository at this point in the history
* fix(fetch): allow string[] as Record value on HeadersInit

* fix(fetch): allow readonly string arrays on HeadersInit

* refact(fetch): move HeadersInit test to test/fetch
  • Loading branch information
dgadelha authored and metcoder95 committed Dec 26, 2022
1 parent 1d88270 commit 828e79a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion test/fetch/headers.js
Expand Up @@ -17,7 +17,7 @@ const {
} = require('../../lib/fetch/constants')

tap.test('Headers initialization', t => {
t.plan(6)
t.plan(7)

t.test('allows undefined', t => {
t.plan(1)
Expand Down Expand Up @@ -97,6 +97,20 @@ tap.test('Headers initialization', t => {
['key', 'value', 'value2']
]), 'throws when too many arguments are passed')
})

t.test('accepts headers as objects with array values', t => {
t.plan(1)
const headers = new Headers({
a: ['1', '2'],
b: ['3', '4'],
c: '5'
})
t.same(headers.entries(), [
['a', '1,2'],
['b', '3,4'],
['c', '5']
])
})
})

tap.test('Headers append', t => {
Expand Down
4 changes: 2 additions & 2 deletions types/fetch.d.ts
Expand Up @@ -42,7 +42,7 @@ export interface BodyMixin {
readonly text: () => Promise<string>
}

export type HeadersInit = string[][] | Record<string, string> | Headers
export type HeadersInit = string[][] | Record<string, string | ReadonlyArray<string>> | Headers

export declare class Headers implements Iterable<[string, string]> {
constructor (init?: HeadersInit)
Expand Down Expand Up @@ -107,7 +107,7 @@ export interface RequestInit {
readonly window?: null
}

export type ReferrerPolicy =
export type ReferrerPolicy =
| ''
| 'no-referrer'
| 'no-referrer-when-downgrade'
Expand Down

0 comments on commit 828e79a

Please sign in to comment.