HttpHeaders class

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.

Constructors

HttpHeaders()

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

Methods

add(String name, Object value) → void
Adds a header value. The header named name will have the value value 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 a List each element of the list will be added separately. For all other types the default toString 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 in name 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 value value 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

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 ==(dynamic other) bool
The equality operator. [...]
inherited

Constants

ACCEPT → const String
"accept"
ACCEPT_CHARSET → const String
"accept-charset"
ACCEPT_ENCODING → const String
"accept-encoding"
ACCEPT_LANGUAGE → const String
"accept-language"
ACCEPT_RANGES → const String
"accept-ranges"
AGE → const String
"age"
ALLOW → const String
"allow"
AUTHORIZATION → const String
"authorization"
CACHE_CONTROL → const String
"cache-control"
CONNECTION → const String
"connection"
CONTENT_ENCODING → const String
"content-encoding"
CONTENT_LANGUAGE → const String
"content-language"
CONTENT_LENGTH → const String
"content-length"
CONTENT_LOCATION → const String
"content-location"
CONTENT_MD5 → const String
"content-md5"
CONTENT_RANGE → const String
"content-range"
CONTENT_TYPE → const String
"content-type"
"cookie"
DATE → const String
"date"
ENTITY_HEADERS → const List<String>
const [ALLOW, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_MD5, CONTENT_RANGE, CONTENT_TYPE, EXPIRES, LAST_MODIFIED]
ETAG → const String
"etag"
EXPECT → const String
"expect"
EXPIRES → const String
"expires"
FROM → const String
"from"
GENERAL_HEADERS → const List<String>
const [CACHE_CONTROL, CONNECTION, DATE, PRAGMA, TRAILER, TRANSFER_ENCODING, UPGRADE, VIA, WARNING]
HOST → const String
"host"
IF_MATCH → const String
"if-match"
IF_MODIFIED_SINCE → const String
"if-modified-since"
IF_NONE_MATCH → const String
"if-none-match"
IF_RANGE → const String
"if-range"
IF_UNMODIFIED_SINCE → const String
"if-unmodified-since"
LAST_MODIFIED → const String
"last-modified"
LOCATION → const String
"location"
MAX_FORWARDS → const String
"max-forwards"
PRAGMA → const String
"pragma"
PROXY_AUTHENTICATE → const String
"proxy-authenticate"
PROXY_AUTHORIZATION → const String
"proxy-authorization"
RANGE → const String
"range"
REFERER → const String
"referer"
REQUEST_HEADERS → const List<String>
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 → const List<String>
const [ACCEPT_RANGES, AGE, ETAG, LOCATION, PROXY_AUTHENTICATE, RETRY_AFTER, SERVER, VARY, WWW_AUTHENTICATE]
RETRY_AFTER → const String
"retry-after"
SERVER → const String
"server"
"set-cookie"
TE → const String
"te"
TRAILER → const String
"trailer"
TRANSFER_ENCODING → const String
"transfer-encoding"
UPGRADE → const String
"upgrade"
USER_AGENT → const String
"user-agent"
VARY → const String
"vary"
VIA → const String
"via"
WARNING → const String
"warning"
WWW_AUTHENTICATE → const String
"www-authenticate"