HttpHeaders class Null safety

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.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
Whether the connection uses chunked transfer encoding.
read / write
contentLength int
The value of the contentLengthHeader header, if any.
read / write
contentType ContentType?
The ContentType of the contentTypeHeader header, if any.
read / write
date DateTime?
The date specified by the dateHeader header, if any.
read / write
expires DateTime?
The date and time specified by the expiresHeader header, if any.
read / write
hashCode int
The hash code for this object.
read-only, inherited
host String?
The value of the hostHeader header, if any.
read / write
ifModifiedSince DateTime?
The date and time specified by the ifModifiedSinceHeader header, if any.
read / write
persistentConnection bool
Whether the connection is persistent (keep-alive).
read / write
port int?
The value of the port part of the hostHeader header, if any.
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

add(String name, Object value, {bool preserveHeaderCase = false}) → void
Adds a header value.
clear() → void
Removes all headers.
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.
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.
removeAll(String name) → void
Removes all values for the specified header name.
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.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String name) List<String>?
The values for the header named name.

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"
accessControlAllowCredentialsHeader → const String
@Since("2.14")
'access-control-allow-credentials'
accessControlAllowHeadersHeader → const String
@Since("2.14")
'access-control-allow-headers'
accessControlAllowMethodsHeader → const String
@Since("2.14")
'access-control-allow-methods'
accessControlAllowOriginHeader → const String
@Since("2.14")
'access-control-allow-origin'
accessControlExposeHeadersHeader → const String
@Since("2.14")
'access-control-expose-headers'
accessControlMaxAgeHeader → const String
@Since("2.14")
'access-control-max-age'
accessControlRequestHeadersHeader → const String
@Since("2.14")
'access-control-request-headers'
accessControlRequestMethodHeader → const String
@Since("2.14")
'access-control-request-method'
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>
[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>
[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>
[acceptHeader, acceptCharsetHeader, acceptEncodingHeader, acceptLanguageHeader, authorizationHeader, expectHeader, fromHeader, hostHeader, ifMatchHeader, ifModifiedSinceHeader, ifNoneMatchHeader, ifRa…
RESPONSE_HEADERS → const List<String>
@Deprecated("Use responseHeaders instead")
responseHeaders
responseHeaders → const List<String>
[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"