温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/globals/Headers
点击访问原文链接

class Headers | globals module | Bun

class Headers | globals module | BunBuildDocsReferenceGuidesBlogDiscord/Globals/HeadersM[Symbol.iterator]MappendPcountMdeleteMentriesMforEachMgetMgetAllMgetSetCookieMhasMkeysMsetMtoJSONMvalues

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Globals/HeadersM[Symbol.iterator]MappendPcountMdeleteMentriesMforEachMgetMgetAllMgetSetCookieMhasMkeysMsetMtoJSONMvalues

class

Headersclass HeadersThis Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs.  You can add to this using methods like append() (see Examples.) In all methods of this interface, header names are matched by case-insensitive byte sequence.

MDN Reference

readonly count: numberGet the total number of headers

[Symbol.iterator](): HeadersIterator[string, string]>;append(name: string,value: string): void;MDN Reference

delete(name: string): void;MDN Reference

entries(): HeadersIterator[string, string]>;Returns an iterator allowing to go through all key/value pairs contained in this object.

forEach(callbackfn: (value: string, key: string, parent: Headers) => void,thisArg?: any): void;get(name: string): null | string;MDN Reference

getAll(name: 'set-cookie' | 'Set-Cookie'): string[];Get all headers matching the name

Only supports "Set-Cookie". All other headers are empty arrays.

@param nameThe header name to get

@returnsAn array of header values

const headers = new Headers(); headers.append("Set-Cookie", "foo=bar"); headers.append("Set-Cookie", "baz=qux"); headers.getAll("Set-Cookie"); // ["foo=bar", "baz=qux"] getSetCookie(): string[];MDN Reference

has(name: string): boolean;MDN Reference

keys(): HeadersIteratorstring>;Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.

set(name: string,value: string): void;MDN Reference

toJSON(): Recordstring, string> & { set-cookie: string[] };Convert Headers to a plain JavaScript object.

About 10x faster than Object.fromEntries(headers.entries())

Called when you run JSON.stringify(headers)

Does not preserve insertion order. Well-known header names are lowercased. Other header names are left as-is.

values(): HeadersIteratorstring>;Returns an iterator allowing to go through all values of the key/value pairs contained in this object.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco

We're hiring →

智能索引记录