AwaitedDOM/ Headers

The Headers interface of the Fetch API allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing headers from the list of the request's headers. 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.
For security reasons, some headers can only be controlled by the user agent. These headers include the forbidden header names and forbidden response header names.
A Headers object also has an associated guard, which takes a value of immutable, request, request-no-cors, response, or none. This affects whether the set(), delete(), and append() methods will mutate the header. For more information see Guard.
You can retrieve a Headers object via the Request.headers and Response.headers properties, and create a new Headers object using the Headers.Headers() constructor.
An object implementing Headers can directly be used in a for...of structure, instead of entries(): for (var p of myHeaders) is equivalent to for (var p of myHeaders.entries()).

Methods

.append(name, value)
W3C

Appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist.

Arguments:

  • name string. The name of the HTTP header you want to add to the Headers object.
  • value string. The value of the HTTP header you want to add.

Returns: Promise<void>

.delete(name)
W3C

Deletes a header from a Headers object.

Arguments:

  • name string. The name of the HTTP header you want to delete from the Headers object.

Returns: Promise<void>

.entries()
W3C

Returns an iterator allowing to go through all key/value pairs contained in this object.

Returns: Promise<>

.forEach()
W3C

Executes a provided function once for each array element.

Returns: Promise<>

.get(name)
W3C

Returns a ByteString sequence of all the values of a header within a Headers object with a given name.

Arguments:

  • name string. The name of the HTTP header whose values you want to retrieve from the Headers object. If the given name is not the name of an HTTP header, this method throws a TypeError. The name is case-insensitive.

Returns: Promise<string>

.has(name)
W3C

Returns a boolean stating whether a Headers object contains a certain header.

Arguments:

  • name string. The name of the HTTP header you want to test for. If the given name is not a valid HTTP header name, this method throws a TypeError.

Returns: Promise<boolean>

.keys()
W3C

Returns an iterator allowing you to go through all keys of the key/value pairs contained in this object.

Returns: Promise<>

.set(name, value)
W3C

Sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist.

Arguments:

  • name string. The name of the HTTP header you want to set to a new value. If the given name is not the name of an HTTP header, this method throws a TypeError.
  • value string. The new value you want to set.

Returns: Promise<void>

.values()
W3C

Returns an iterator allowing you to go through all values of the key/value pairs contained in this object.

Returns: Promise<>

Edit this page on GitHub