Headers class Null safety

The 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 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 object via the Request.headers and Response.headers properties, and create a new object using the Headers.Headers() constructor.

An object implementing 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()). Note: you can find more out about the available headers by reading our HTTP headers reference.

Annotations

Constructors

Headers([dynamic init])
factory

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

append(String name, String value) Object
Appends a new value onto an existing header inside a Headers object, or adds the header if it does not already exist. myHeaders.append(name, value); Creating an empty Headers object is simple: [...]
delete(String name) Object
Deletes a header from a Headers object. myHeaders.delete(name); Creating an empty Headers object is simple: [...]
has(String name) bool
Returns a boolean stating whether a Headers object contains a certain header. myHeaders.has(name); Creating an empty Headers object is simple: [...]
mGet(String name) String?
Returns a ByteString sequence of all the values of a header within a Headers object with a given name. myHeaders.get(name); Creating an empty Headers object is simple: [...]
@JS('get')
mSet(String name, String value) Object
Sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist. myHeaders.set(name, value); Creating an empty Headers object is simple: [...]
@JS('set')
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
A string representation of this object. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited