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

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

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'
ageHeader → const String
"age"
allowHeader → const String
"allow"
authorizationHeader → const String
"authorization"
cacheControlHeader → const String
"cache-control"
connectionHeader → const String
"connection"
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 → const String
"cookie"
dateHeader → const String
"date"
entityHeaders → const List<String>
[allowHeader, contentEncodingHeader, contentLanguageHeader, contentLengthHeader, contentLocationHeader, contentMD5Header, contentRangeHeader, contentTypeHeader, expiresHeader, lastModifiedHeader]
etagHeader → const String
"etag"
expectHeader → const String
"expect"
expiresHeader → const String
"expires"
fromHeader → const String
"from"
generalHeaders → const List<String>
[cacheControlHeader, connectionHeader, dateHeader, pragmaHeader, trailerHeader, transferEncodingHeader, upgradeHeader, viaHeader, warningHeader]
hostHeader → const String
"host"
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"
lastModifiedHeader → const String
"last-modified"
locationHeader → const String
"location"
maxForwardsHeader → const String
"max-forwards"
pragmaHeader → const String
"pragma"
proxyAuthenticateHeader → const String
"proxy-authenticate"
proxyAuthorizationHeader → const String
"proxy-authorization"
rangeHeader → const String
"range"
refererHeader → const String
"referer"
requestHeaders → const List<String>
[acceptHeader, acceptCharsetHeader, acceptEncodingHeader, acceptLanguageHeader, authorizationHeader, expectHeader, fromHeader, hostHeader, ifMatchHeader, ifModifiedSinceHeader, ifNoneMatchHeader, ifRa…
responseHeaders → const List<String>
[acceptRangesHeader, ageHeader, etagHeader, locationHeader, proxyAuthenticateHeader, retryAfterHeader, serverHeader, varyHeader, wwwAuthenticateHeader]
retryAfterHeader → const String
"retry-after"
serverHeader → const String
"server"
setCookieHeader → const String
"set-cookie"
teHeader → const String
"te"
trailerHeader → const String
"trailer"
transferEncodingHeader → const String
"transfer-encoding"
upgradeHeader → const String
"upgrade"
userAgentHeader → const String
"user-agent"
varyHeader → const String
"vary"
viaHeader → const String
"via"
warningHeader → const String
"warning"
wwwAuthenticateHeader → const String
"www-authenticate"