Skip to content

http.Function.toAryHeaders

github-actions[bot] edited this page Jun 8, 2026 · 2 revisions

@zenstone/ts-utils / http / toAryHeaders

Function: toAryHeaders()

toAryHeaders(headers?): AryHeaderItem[]

Defined in: src/http/headers.ts:38

将任意 HeadersInit 转为多个 AryHeaderItem 的数组

浏览器环境或 bun 环境下,HeadersInit 类型如下:

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

需要注意的是,在使用 headers<Headers>.entries() 时,Header 的 Key 会转为小写:

const h = new Headers();
h.set('Content-Type', 'application/json');
console.log([...h.keys()]); // 将输出 => ['content-type']

所以,当输入的 headers[string, string][]Record<string, string> 类 型时,应该确保 Key 为小写。即:

const h1 = [['content-Type', 'application/json']];
const h2 = { 'content-Type': 'application/json' };

Parameters

headers?

HeadersInitInput

Returns

AryHeaderItem[]

Clone this wiki locally