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.cacheControlHeader,
                    'max-age=3600, must-revalidate');

To retrieve the value of a header use the value() method:

print(request.headers.value(HttpHeaders.userAgentHeader));

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
hashCode int
The hash code for this object.
read-onlyinherited
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
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

add(String name, Object value, {bool preserveHeaderCase = false}) → void
Adds a header value.
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 action(String name, List<String> values)) → void
Performs the action on each header.
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.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
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, {bool preserveHeaderCase = false}) → void
Sets the header name to value.
toString() String
A string representation of this object.
inherited
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.

Operators

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

Constants

ACCEPT → const String
acceptHeader
ACCEPT_CHARSET → const String
acceptCharsetHeader
ACCEPT_ENCODING → const String
acceptEncodingHeader
ACCEPT_LANGUAGE → const String
acceptLanguageHeader
ACCEPT_RANGES → const String
acceptRangesHeader
acceptCharsetHeader → const String
"accept-charset"
acceptEncodingHeader → const String
"accept-encoding"
acceptHeader → const String
"accept"
acceptLanguageHeader → const String
"accept-language"
acceptRangesHeader → const String
"accept-ranges"
AGE → const String
ageHeader
ageHeader → const String
"age"
ALLOW → const String
allowHeader
allowHeader → const String
"allow"
AUTHORIZATION → const String
authorizationHeader
authorizationHeader → const String
"authorization"
CACHE_CONTROL → const String
cacheControlHeader
cacheControlHeader → const String
"cache-control"
CONNECTION → const String
connectionHeader
connectionHeader → const String
"connection"
CONTENT_ENCODING → const String
contentEncodingHeader
CONTENT_LANGUAGE → const String
contentLanguageHeader
CONTENT_LENGTH → const String
contentLengthHeader
CONTENT_LOCATION → const String
contentLocationHeader
CONTENT_MD5 → const String
contentMD5Header
CONTENT_RANGE → const String
contentRangeHeader
CONTENT_TYPE → const String
contentTypeHeader
contentEncodingHeader → const String
"content-encoding"
contentLanguageHeader → const String
"content-language"
contentLengthHeader → const String
"content-length"
contentLocationHeader → const String
"content-location"
contentMD5Header → const String
"content-md5"
contentRangeHeader → const String
"content-range"
contentTypeHeader → const String
"content-type"
cookieHeader
cookieHeader → const String
"cookie"
DATE → const String
dateHeader
dateHeader → const String
"date"
ENTITY_HEADERS → const List<String>
entityHeaders
entityHeaders → const List<String>
const [allowHeader, contentEncodingHeader, contentLanguageHeader, contentLengthHeader, contentLocationHeader, contentMD5Header, contentRangeHeader, contentTypeHeader, expiresHeader, lastModifiedHeader…
ETAG → const String
etagHeader
etagHeader → const String
"etag"
EXPECT → const String
expectHeader
expectHeader → const String
"expect"
EXPIRES → const String
expiresHeader
expiresHeader → const String
"expires"
FROM → const String
fromHeader
fromHeader → const String
"from"
GENERAL_HEADERS → const List<String>
generalHeaders
generalHeaders → const List<String>
const [cacheControlHeader, connectionHeader, dateHeader, pragmaHeader, trailerHeader, transferEncodingHeader, upgradeHeader, viaHeader, warningHeader]
HOST → const String
hostHeader
hostHeader → const String
"host"
IF_MATCH → const String
ifMatchHeader
IF_MODIFIED_SINCE → const String
ifModifiedSinceHeader
IF_NONE_MATCH → const String
ifNoneMatchHeader
IF_RANGE → const String
ifRangeHeader
IF_UNMODIFIED_SINCE → const String
ifUnmodifiedSinceHeader
ifMatchHeader → const String
"if-match"
ifModifiedSinceHeader → const String
"if-modified-since"
ifNoneMatchHeader → const String
"if-none-match"
ifRangeHeader → const String
"if-range"
ifUnmodifiedSinceHeader → const String
"if-unmodified-since"
LAST_MODIFIED → const String
lastModifiedHeader
lastModifiedHeader → const String
"last-modified"
LOCATION → const String
locationHeader
locationHeader → const String
"location"
MAX_FORWARDS → const String
maxForwardsHeader
maxForwardsHeader → const String
"max-forwards"
PRAGMA → const String
pragmaHeader
pragmaHeader → const String
"pragma"
PROXY_AUTHENTICATE → const String
proxyAuthenticateHeader
PROXY_AUTHORIZATION → const String
proxyAuthorizationHeader
proxyAuthenticateHeader → const String
"proxy-authenticate"
proxyAuthorizationHeader → const String
"proxy-authorization"
RANGE → const String
rangeHeader
rangeHeader → const String
"range"
REFERER → const String
refererHeader
refererHeader → const String
"referer"
REQUEST_HEADERS → const List<String>
requestHeaders
requestHeaders → const List<String>
const [acceptHeader, acceptCharsetHeader, acceptEncodingHeader, acceptLanguageHeader, authorizationHeader, expectHeader, fromHeader, hostHeader, ifMatchHeader, ifModifiedSinceHeader, ifNoneMatchHeader…
RESPONSE_HEADERS → const List<String>
responseHeaders
responseHeaders → const List<String>
const [acceptRangesHeader, ageHeader, etagHeader, locationHeader, proxyAuthenticateHeader, retryAfterHeader, serverHeader, varyHeader, wwwAuthenticateHeader]
RETRY_AFTER → const String
retryAfterHeader
retryAfterHeader → const String
"retry-after"
SERVER → const String
serverHeader
serverHeader → const String
"server"
setCookieHeader
setCookieHeader → const String
"set-cookie"
TE → const String
teHeader
teHeader → const String
"te"
TRAILER → const String
trailerHeader
trailerHeader → const String
"trailer"
TRANSFER_ENCODING → const String
transferEncodingHeader
transferEncodingHeader → const String
"transfer-encoding"
UPGRADE → const String
upgradeHeader
upgradeHeader → const String
"upgrade"
USER_AGENT → const String
userAgentHeader
userAgentHeader → const String
"user-agent"
VARY → const String
varyHeader
varyHeader → const String
"vary"
VIA → const String
viaHeader
viaHeader → const String
"via"
WARNING → const String
warningHeader
warningHeader → const String
"warning"
WWW_AUTHENTICATE → const String
wwwAuthenticateHeader
wwwAuthenticateHeader → const String
"www-authenticate"