HttpHeaders class

Headers for HTTP requests and responses.

Headers for HTTP requests and responses.

In some situations, headers are immutable:

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()

Constants

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

Instance Properties

date DateTime
read / write
Gets and sets the date. The value of this property will reflect the 'date' header.
expires DateTime
read / write
Gets and sets the expiry date. The value of this property will reflect the 'expires' header.
ifModifiedSince DateTime
read / write
Gets and sets the "if-modified-since" date. The value of this property will reflect the "if-modified-since" header.
host String
read / write
Gets and sets the host part of the 'host' header for the connection.
port int
read / write
Gets and sets the port part of the 'host' header for the connection.
contentType ContentType
read / write
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.
contentLength int
read / write
Gets and sets the content length header value.
persistentConnection bool
read / write
Gets and sets the persistent connection header value.
chunkedTransferEncoding bool
read / write
Gets and sets the chunked transfer encoding header value.

Instance Methods

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.
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.
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.
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.
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.
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.

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.