Headers extension type
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 Headers.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 and .
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 Headers.set, Headers.delete, and Headers.append
methods will mutate the header. For more information see .
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 Headers.entries
: for (const p of myHeaders)
is
equivalent to for (const p of myHeaders.entries())
.
Note: you can find out more about the available headers by reading our HTTP headers reference.
- on
- Implemented types
- Available extensions
Constructors
- Headers([HeadersInit init])
-
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
append(
String name, String value) → void -
The
append()
method of the Headers interface appends a new value onto an existing header inside aHeaders
object, or adds the header if it does not already exist. -
delete(
String name) → void -
The
delete()
method of the Headers interface deletes a header from the currentHeaders
object. -
get(
String name) → String? -
The
get()
method of the Headers interface returns a byte string of all the values of a header within aHeaders
object with a given name. If the requested header doesn't exist in theHeaders
object, it returnsnull
. -
getSetCookie(
) → JSArray< JSString> -
The
getSetCookie()
method of the Headers interface returns an array containing the values of all headers associated with a response. This allows Headers objects to handle having multipleSet-Cookie
headers, which wasn't possible prior to its implementation. -
has(
String name) → bool -
The
has()
method of the Headers interface returns a boolean stating whether aHeaders
object contains a certain header. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
set(
String name, String value) → void -
The
set()
method of the Headers interface sets a new value for an existing header inside aHeaders
object, or adds the header if it does not already exist. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited