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.
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. f
to each header. The header name passed in name
will be all lower case. 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. name
will have all its values cleared before the value value
is added as its value. null
will be returned. If the header has more than one value an exception is thrown. name
. If there is no header with the provided name, null
will be returned. acceptHeader
acceptCharsetHeader
acceptEncodingHeader
acceptLanguageHeader
acceptRangesHeader
"accept-charset"
"accept-encoding"
"accept"
"accept-language"
"accept-ranges"
ageHeader
"age"
allowHeader
"allow"
authorizationHeader
"authorization"
cacheControlHeader
"cache-control"
connectionHeader
"connection"
contentEncodingHeader
contentLanguageHeader
contentLengthHeader
contentLocationHeader
contentMD5Header
contentRangeHeader
contentTypeHeader
"content-encoding"
"content-language"
"content-length"
"content-location"
"content-md5"
"content-range"
"content-type"
cookieHeader
"cookie"
dateHeader
"date"
entityHeaders
const [allowHeader, contentEncodingHeader, contentLanguageHeader, contentLengthHeader, contentLocationHeader, contentMD5Header, contentRangeHeader, contentTypeHeader, expiresHeader, lastModifiedHeader…
etagHeader
"etag"
expectHeader
"expect"
expiresHeader
"expires"
fromHeader
"from"
generalHeaders
const [cacheControlHeader, connectionHeader, dateHeader, pragmaHeader, trailerHeader, transferEncodingHeader, upgradeHeader, viaHeader, warningHeader]
hostHeader
"host"
ifMatchHeader
ifModifiedSinceHeader
ifNoneMatchHeader
ifRangeHeader
ifUnmodifiedSinceHeader
"if-match"
"if-modified-since"
"if-none-match"
"if-range"
"if-unmodified-since"
lastModifiedHeader
"last-modified"
locationHeader
"location"
maxForwardsHeader
"max-forwards"
pragmaHeader
"pragma"
proxyAuthenticateHeader
proxyAuthorizationHeader
"proxy-authenticate"
"proxy-authorization"
rangeHeader
"range"
refererHeader
"referer"
requestHeaders
const [acceptHeader, acceptCharsetHeader, acceptEncodingHeader, acceptLanguageHeader, authorizationHeader, expectHeader, fromHeader, hostHeader, ifMatchHeader, ifModifiedSinceHeader, ifNoneMatchHeader…
responseHeaders
const [acceptRangesHeader, ageHeader, etagHeader, locationHeader, proxyAuthenticateHeader, retryAfterHeader, serverHeader, varyHeader, wwwAuthenticateHeader]
retryAfterHeader
"retry-after"
serverHeader
"server"
setCookieHeader
"set-cookie"
teHeader
"te"
trailerHeader
"trailer"
transferEncodingHeader
"transfer-encoding"
upgradeHeader
"upgrade"
userAgentHeader
"user-agent"
varyHeader
"vary"
viaHeader
"via"
warningHeader
"warning"
wwwAuthenticateHeader
"www-authenticate"
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-io/HttpHeaders-class.html