From 828e79affcf4e8a1c28fbed8eee9f1088f78616d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Douglas=20Gad=C3=AAlha?= Date: Mon, 28 Feb 2022 05:44:44 -0300 Subject: [PATCH] Allow string[] as Record value on HeadersInit (#1244) * 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 --- test/fetch/headers.js | 16 +++++++++++++++- types/fetch.d.ts | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/test/fetch/headers.js b/test/fetch/headers.js index e2a04fa7b93..044e4d1508b 100644 --- a/test/fetch/headers.js +++ b/test/fetch/headers.js @@ -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) @@ -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 => { diff --git a/types/fetch.d.ts b/types/fetch.d.ts index 45f244b3278..2057c8c8e7f 100644 --- a/types/fetch.d.ts +++ b/types/fetch.d.ts @@ -42,7 +42,7 @@ export interface BodyMixin { readonly text: () => Promise } -export type HeadersInit = string[][] | Record | Headers +export type HeadersInit = string[][] | Record> | Headers export declare class Headers implements Iterable<[string, string]> { constructor (init?: HeadersInit) @@ -107,7 +107,7 @@ export interface RequestInit { readonly window?: null } -export type ReferrerPolicy = +export type ReferrerPolicy = | '' | 'no-referrer' | 'no-referrer-when-downgrade'