Headers for HTTP requests and responses.
In some situations, headers are immutable:
-
HttpRequest and HttpClientResponse always have immutable headers.
-
HttpResponse and HttpClientRequest have immutable headers from the moment the body is written to.
In these situations, the mutating methods throw exceptions.
For all operations on HTTP headers the header name is case-insensitive.
To set the value of a header use the set()
method:
request.headers.set(HttpHeaders.CACHE_CONTROL,
'max-age=3600, must-revalidate');
To retrieve the value of a header use the value()
method:
print(request.headers.value(HttpHeaders.USER_AGENT));
An HttpHeaders object holds a list of values for each name
as the standard allows. In most cases a name holds only a single value,
The most common mode of operation is to use set()
for setting a value,
and value()
for retrieving a value.
Constants
- ACCEPT → dynamic
-
"accept"
- ACCEPT_CHARSET → dynamic
-
"accept-charset"
- ACCEPT_ENCODING → dynamic
-
"accept-encoding"
- ACCEPT_LANGUAGE → dynamic
-
"accept-language"
- ACCEPT_RANGES → dynamic
-
"accept-ranges"
- AGE → dynamic
-
"age"
- ALLOW → dynamic
-
"allow"
- AUTHORIZATION → dynamic
-
"authorization"
- CACHE_CONTROL → dynamic
-
"cache-control"
- CONNECTION → dynamic
-
"connection"
- CONTENT_ENCODING → dynamic
-
"content-encoding"
- CONTENT_LANGUAGE → dynamic
-
"content-language"
- CONTENT_LENGTH → dynamic
-
"content-length"
- CONTENT_LOCATION → dynamic
-
"content-location"
- CONTENT_MD5 → dynamic
-
"content-md5"
- CONTENT_RANGE → dynamic
-
"content-range"
- CONTENT_TYPE → dynamic
-
"content-type"
- COOKIE → dynamic
-
"cookie"
- DATE → dynamic
-
"date"
- ENTITY_HEADERS → dynamic
-
const [ALLOW, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_MD5, CONTENT_RANGE, CONTENT_TYPE, EXPIRES, LAST_MODIFIED]
- ETAG → dynamic
-
"etag"
- EXPECT → dynamic
-
"expect"
- EXPIRES → dynamic
-
"expires"
- FROM → dynamic
-
"from"
- GENERAL_HEADERS → dynamic
-
const [CACHE_CONTROL, CONNECTION, DATE, PRAGMA, TRAILER, TRANSFER_ENCODING, UPGRADE, VIA, WARNING]
- HOST → dynamic
-
"host"
- IF_MATCH → dynamic
-
"if-match"
- IF_MODIFIED_SINCE → dynamic
-
"if-modified-since"
- IF_NONE_MATCH → dynamic
-
"if-none-match"
- IF_RANGE → dynamic
-
"if-range"
- IF_UNMODIFIED_SINCE → dynamic
-
"if-unmodified-since"
- LAST_MODIFIED → dynamic
-
"last-modified"
- LOCATION → dynamic
-
"location"
- MAX_FORWARDS → dynamic
-
"max-forwards"
- PRAGMA → dynamic
-
"pragma"
- PROXY_AUTHENTICATE → dynamic
-
"proxy-authenticate"
- PROXY_AUTHORIZATION → dynamic
-
"proxy-authorization"
- RANGE → dynamic
-
"range"
- REFERER → dynamic
-
"referer"
- REQUEST_HEADERS → dynamic
-
const [ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, AUTHORIZATION, EXPECT, FROM, HOST, IF_MATCH, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, MAX_FORWARDS, PROXY_AUTHO…
- RESPONSE_HEADERS → dynamic
-
const [ACCEPT_RANGES, AGE, ETAG, LOCATION, PROXY_AUTHENTICATE, RETRY_AFTER, SERVER, VARY, WWW_AUTHENTICATE]
- RETRY_AFTER → dynamic
-
"retry-after"
- SERVER → dynamic
-
"server"
- SET_COOKIE → dynamic
-
"set-cookie"
- TE → dynamic
-
"te"
- TRAILER → dynamic
-
"trailer"
- TRANSFER_ENCODING → dynamic
-
"transfer-encoding"
- UPGRADE → dynamic
-
"upgrade"
- USER_AGENT → dynamic
-
"user-agent"
- VARY → dynamic
-
"vary"
- VIA → dynamic
-
"via"
- WARNING → dynamic
-
"warning"
- WWW_AUTHENTICATE → dynamic
-
"www-authenticate"
Constructors
Properties
- chunkedTransferEncoding → bool
-
Gets and sets the chunked transfer encoding header value.
read / write - contentLength → int
-
Gets and sets the content length header value.
read / write - contentType → ContentType
-
Gets and sets the content type. Note that the content type in the header will only be updated if this field is set directly. Mutating the returned current value will have no effect.
read / write - date → DateTime
-
Gets and sets the date. The value of this property will reflect the 'date' header.
read / write - expires → DateTime
-
Gets and sets the expiry date. The value of this property will reflect the 'expires' header.
read / write - host → String
-
Gets and sets the host part of the 'host' header for the connection.
read / write - ifModifiedSince → DateTime
-
Gets and sets the "if-modified-since" date. The value of this property will reflect the "if-modified-since" header.
read / write - persistentConnection → bool
-
Gets and sets the persistent connection header value.
read / write - port → int
-
Gets and sets the port part of the 'host' header for the connection.
read / write - 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
Operators
-
operator [](
String name) → List<String> -
Returns the list of values for the header named
name
. If there is no header with the provided name,null
will be returned. -
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
add(
String name, Object value) → void -
Adds a header value. The header named
name
will have the valuevalue
added to its list of values. Some headers are single valued, and for these adding a value will replace the previous value. If the value is of type DateTime a HTTP date format will be applied. If the value is aList
each element of the list will be added separately. For all other types the defaulttoString
method will be used. -
clear(
) → void -
Remove all headers. Some headers have system supplied values and for these the system supplied values will still be added to the collection of values for the header.
-
forEach(
void f(String name, List<String> values)) → void -
Enumerates the headers, applying the function
f
to each header. The header name passed inname
will be all lower case. -
noFolding(
String name) → void -
Disables folding for the header named
name
when sending the HTTP header. By default, multiple header values are folded into a single header line by separating the values with commas. The 'set-cookie' header has folding disabled by default. -
remove(
String name, Object value) → void -
Removes a specific value for a header name. Some headers have system supplied values and for these the system supplied values will still be added to the collection of values for the header.
-
removeAll(
String name) → void -
Removes all values for the specified header name. Some headers have system supplied values and for these the system supplied values will still be added to the collection of values for the header.
-
set(
String name, Object value) → void -
Sets a header. The header named
name
will have all its values cleared before the valuevalue
is added as its value. -
value(
String name) → String -
Convenience method for the value for a single valued header. If there is no header with the provided name,
null
will be returned. If the header has more than one value an exception is thrown. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
toString(
) → String -
Returns a string representation of this object.
inherited