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. 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.Headers
object via the Request.headers
and Response.headers
properties, and create a new Headers
object using the Headers.Headers()
constructor.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())
.Appends a new value onto an existing header inside a Headers
object, or adds the header if it does not already exist.
string
. The name of the HTTP header you want to add to the Headers
object.string
. The value of the HTTP header you want to add.Promise<void>
Deletes a header from a Headers
object.
string
. The name of the HTTP header you want to delete from the Headers
object.Promise<void>
Returns an iterator
allowing to go through all key/value pairs contained in this object.
Promise<>
Executes a provided function once for each array element.
Promise<>
Returns a ByteString
sequence of all the values of a header within a Headers
object with a given 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.Promise<string>
Returns a boolean stating whether a Headers
object contains a certain header.
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
.Promise<boolean>
Returns an iterator
allowing you to go through all keys of the key/value pairs contained in this object.
Promise<>
Sets a new value for an existing header inside a Headers
object, or adds the header if it does not already exist.
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
.string
. The new value you want to set.Promise<void>
Returns an iterator
allowing you to go through all values of the key/value pairs contained in this object.
Promise<>