Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Headers — HTTP headers

Headers stores HTTP headers for Fetch, supporting reading, appending, replacement, deletion, and iteration.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

new Headers(init?)
headers.append(name, value)
headers.set(name, value)
headers.get(name)
headers.has(name)
headers.delete(name)
for (const [name, value] of headers) { /* ... */ }

Headers is a Fetch interface, not ECMAScript. Its constructor accepts an object, pairs, or another Headers. Names are case-insensitive. Fetch trims only HTTP whitespace bytes from the start and end of a value: horizontal tab (0x09), line feed (0x0A), carriage return (0x0D), and space (0x20). A nonbreaking space (U+00A0) at either end is accepted and retained.

append() adds a value; set() replaces all values for a name. get() joins values with , , returning null when absent. has() checks presence; delete() removes. The object is iterable.

Invalid names or values cause TypeError. Request and response headers have restrictions; successfully modifying a standalone Headers does not guarantee transmission.

Examples

const headers = new Headers({ "X-Tag": " alpha " });
headers.append("x-tag", "beta");
console.log(headers.get("X-TAG"));
headers.set("x-tag", "gamma");
console.log(headers.get("x-tag"));
headers.delete("x-tag");
console.log(headers.has("x-tag"));
console.log(headers.get("x-tag"));

Result

alpha, beta
gamma
false
null

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources