Headers class
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()
. 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.
You can retrieve a Headers object via the Request.headers
and
ResponseInstanceMembers.headers properties, and create
a new Headers object using the Headers()
constructor.
- Available extensions
- Annotations
-
- @JS()
- @staticInterop
Constructors
- Headers.new()
-
Creates a new Headers object.
factory
-
Headers.fromArray(List<
List< init)String> > -
Warning: available only with Dart 3.0 or higher.
Creates Headers from array of 2 items arrays.
factory
-
Headers.fromMap(Map<
String, String> init) -
Warning: available only with Dart 3.0 or higher.
Creates Headers from Map.
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 -
Available on Headers, provided by the HeadersInstanceMembers extension
Appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist. -
delete(
String name) → void -
Available on Headers, provided by the HeadersInstanceMembers extension
Deletes a header from a Headers object. -
entries(
) → IteratorWrapper< List< String> > -
Available on Headers, provided by the HeadersInstanceMembers extension
Returns an IteratorWrapper allowing to go through all key/value pairs contained in this object. -
get(
String name) → String? -
Available on Headers, provided by the HeadersInstanceMembers extension
Returns a String sequence of all the values of a header within a Headers object with a given name. -
has(
String name) → bool -
Available on Headers, provided by the HeadersInstanceMembers extension
Returns a bool stating whether a Headers object contains a certain header. -
keys(
) → IteratorWrapper< String> -
Available on Headers, provided by the HeadersInstanceMembers extension
Returns an IteratorWrapper allowing you to go through all keys of the key/value pairs contained in this object. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
set(
String name, String value) → void -
Available on Headers, provided by the HeadersInstanceMembers extension
Sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist. -
toString(
) → String -
A string representation of this object.
inherited
-
values(
) → IteratorWrapper< String> -
Available on Headers, provided by the HeadersInstanceMembers extension
Returns an IteratorWrapper allowing you to go through all values of the key/value pairs contained in this object.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited