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