Headers for HTTP requests and responses.
In some situations, headers are immutable:
HttpRequest andHttpClientResponse always have immutable headers.
HttpResponse andHttpClientRequest have immutable headersfrom the moment the body is written to.
In these situations, the mutating methods throw exceptions.
For all operations on HTTP headers the header name iscase-insensitive.
To set the value of a header use theset() method:
request.headers.set(HttpHeaders.cacheControlHeader, 'max-age=3600, must-revalidate');To retrieve the value of a header use thevalue() method:
print(request.headers.value(HttpHeaders.userAgentHeader));AnHttpHeaders object holds a list of values for each nameas the standard allows. In most cases a name holds only a single value,The most common mode of operation is to useset() for setting a value,andvalue() for retrieving a value.
Properties
- chunkedTransferEncoding↔bool
- Whether the connection uses chunked transfer encoding.getter/setter pair
- contentLength↔int
- The value of thecontentLengthHeader header, if any.getter/setter pair
- contentType↔ContentType?
- TheContentType of thecontentTypeHeader header, if any.getter/setter pair
- date↔DateTime?
- The date specified by thedateHeader header, if any.getter/setter pair
- expires↔DateTime?
- The date and time specified by theexpiresHeader header, if any.getter/setter pair
- hashCode→int
- The hash code for this object.no setterinherited
- host↔String?
- The value of thehostHeader header, if any.getter/setter pair
- ifModifiedSince↔DateTime?
- The date and time specified by theifModifiedSinceHeader header, if any.getter/setter pair
- persistentConnection↔bool
- Whether the connection is persistent (keep-alive).getter/setter pair
- port↔int?
- The value of the port part of thehostHeader header, if any.getter/setter pair
- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
Methods
- add(
Stringname,Objectvalue, {boolpreserveHeaderCase =false})→ void - Adds a header value.
- clear(
)→ void - Removes all headers.
- forEach(
voidaction(Stringname,List< String> values))→ void - Performs the
actionon each header. - noFolding(
Stringname)→ void - Disables folding for the header named
namewhen sending the HTTP header. - noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- remove(
Stringname,Objectvalue)→ void - Removes a specific value for a header name.
- removeAll(
Stringname)→ void - Removes all values for the specified header name.
- set(
Stringname,Objectvalue, {boolpreserveHeaderCase =false})→ void - Sets the header
nametovalue. - toString(
)→String - A string representation of this object.inherited
- value(
Stringname)→String? - Convenience method for the value for a single valued header.
Operators
- operator ==(
Objectother)→bool - The equality operator.inherited
- operator [](
Stringname)→List< String> ? - The values for the header named
name.
Constants
- acceptCharsetHeader→ constString
- acceptEncodingHeader→ constString
- acceptHeader→ constString
- acceptLanguageHeader→ constString
- acceptRangesHeader→ constString
- accessControlAllowCredentialsHeader→ constString
- accessControlAllowHeadersHeader→ constString
- accessControlAllowMethodsHeader→ constString
- accessControlAllowOriginHeader→ constString
- accessControlExposeHeadersHeader→ constString
- accessControlMaxAgeHeader→ constString
- accessControlRequestHeadersHeader→ constString
- accessControlRequestMethodHeader→ constString
- ageHeader→ constString
- allowHeader→ constString
- authorizationHeader→ constString
- cacheControlHeader→ constString
- connectionHeader→ constString
- contentDisposition→ constString
- contentEncodingHeader→ constString
- contentLanguageHeader→ constString
- contentLengthHeader→ constString
- contentLocationHeader→ constString
- contentMD5Header→ constString
- contentRangeHeader→ constString
- contentTypeHeader→ constString
- cookieHeader→ constString
- dateHeader→ constString
- entityHeaders→ constList<
String> - etagHeader→ constString
- expectHeader→ constString
- expiresHeader→ constString
- fromHeader→ constString
- generalHeaders→ constList<
String> - hostHeader→ constString
- ifMatchHeader→ constString
- ifModifiedSinceHeader→ constString
- ifNoneMatchHeader→ constString
- ifRangeHeader→ constString
- ifUnmodifiedSinceHeader→ constString
- lastModifiedHeader→ constString
- locationHeader→ constString
- maxForwardsHeader→ constString
- pragmaHeader→ constString
- proxyAuthenticateHeader→ constString
- proxyAuthorizationHeader→ constString
- rangeHeader→ constString
- refererHeader→ constString
- requestHeaders→ constList<
String> - responseHeaders→ constList<
String> - retryAfterHeader→ constString
- serverHeader→ constString
- setCookieHeader→ constString
- teHeader→ constString
- trailerHeader→ constString
- transferEncodingHeader→ constString
- upgradeHeader→ constString
- userAgentHeader→ constString
- varyHeader→ constString
- viaHeader→ constString
- warningHeader→ constString
- wwwAuthenticateHeader→ constString