Dart API Referencedart:ioHttpHeaders

HttpHeaders abstract class

Access to the HTTP headers for requests and responses. In some situations the headers will be immutable and the mutating methods will then throw exceptions.

For all operations on HTTP headers the header name is case-insensitive.

abstract class HttpHeaders {
 static const ACCEPT = "accept";
 static const ACCEPT_CHARSET = "accept-charset";
 static const ACCEPT_ENCODING = "accept-encoding";
 static const ACCEPT_LANGUAGE = "accept-language";
 static const ACCEPT_RANGES = "accept-ranges";
 static const AGE = "age";
 static const ALLOW = "allow";
 static const AUTHORIZATION = "authorization";
 static const CACHE_CONTROL = "cache-control";
 static const CONNECTION = "connection";
 static const CONTENT_ENCODING = "content-encoding";
 static const CONTENT_LANGUAGE = "content-language";
 static const CONTENT_LENGTH = "content-length";
 static const CONTENT_LOCATION = "content-location";
 static const CONTENT_MD5 = "content-md5";
 static const CONTENT_RANGE = "content-range";
 static const CONTENT_TYPE = "content-type";
 static const DATE = "date";
 static const ETAG = "etag";
 static const EXPECT = "expect";
 static const EXPIRES = "expires";
 static const FROM = "from";
 static const HOST = "host";
 static const IF_MATCH = "if-match";
 static const IF_MODIFIED_SINCE = "if-modified-since";
 static const IF_NONE_MATCH = "if-none-match";
 static const IF_RANGE = "if-range";
 static const IF_UNMODIFIED_SINCE = "if-unmodified-since";
 static const LAST_MODIFIED = "last-modified";
 static const LOCATION = "location";
 static const MAX_FORWARDS = "max-forwards";
 static const PRAGMA = "pragma";
 static const PROXY_AUTHENTICATE = "proxy-authenticate";
 static const PROXY_AUTHORIZATION = "proxy-authorization";
 static const RANGE = "range";
 static const REFERER = "referer";
 static const RETRY_AFTER = "retry-after";
 static const SERVER = "server";
 static const TE = "te";
 static const TRAILER = "trailer";
 static const TRANSFER_ENCODING = "transfer-encoding";
 static const UPGRADE = "upgrade";
 static const USER_AGENT = "user-agent";
 static const VARY = "vary";
 static const VIA = "via";
 static const WARNING = "warning";
 static const WWW_AUTHENTICATE = "www-authenticate";

 // Cookie headers from RFC 6265.
 static const COOKIE = "cookie";
 static const SET_COOKIE = "set-cookie";

 static const GENERAL_HEADERS = const [CACHE_CONTROL,
                                       CONNECTION,
                                       DATE,
                                       PRAGMA,
                                       TRAILER,
                                       TRANSFER_ENCODING,
                                       UPGRADE,
                                       VIA,
                                       WARNING];

 static const ENTITY_HEADERS = const [ALLOW,
                                      CONTENT_ENCODING,
                                      CONTENT_LANGUAGE,
                                      CONTENT_LENGTH,
                                      CONTENT_LOCATION,
                                      CONTENT_MD5,
                                      CONTENT_RANGE,
                                      CONTENT_TYPE,
                                      EXPIRES,
                                      LAST_MODIFIED];


 static const RESPONSE_HEADERS = const [ACCEPT_RANGES,
                                        AGE,
                                        ETAG,
                                        LOCATION,
                                        PROXY_AUTHENTICATE,
                                        RETRY_AFTER,
                                        SERVER,
                                        VARY,
                                        WWW_AUTHENTICATE];

 static const REQUEST_HEADERS = const [ACCEPT,
                                       ACCEPT_CHARSET,
                                       ACCEPT_ENCODING,
                                       ACCEPT_LANGUAGE,
                                       AUTHORIZATION,
                                       EXPECT,
                                       FROM,
                                       HOST,
                                       IF_MATCH,
                                       IF_MODIFIED_SINCE,
                                       IF_NONE_MATCH,
                                       IF_RANGE,
                                       IF_UNMODIFIED_SINCE,
                                       MAX_FORWARDS,
                                       PROXY_AUTHORIZATION,
                                       RANGE,
                                       REFERER,
                                       TE,
                                       USER_AGENT];

 /**
  * Returns the list of values for the header named [name]. If there
  * is no header with the provided name, [:null:] will be returned.
  */
 List<String> operator[](String name);

 /**
  * 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.
  */
 String value(String name);

 /**
  * 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.
  */
 void add(String name, Object value);

 /**
  * Sets a header. The header named [name] will have all its values
  * cleared before the value [value] is added as its value.
  */
 void set(String name, Object value);

 /**
  * 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.
  */
 void remove(String name, Object value);

 /**
  * 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.
  */
 void removeAll(String name);

 /**
  * Enumerates the headers, applying the function [f] to each
  * header. The header name passed in [:name:] will be all lower
  * case.
  */
 void forEach(void f(String name, List<String> values));

 /**
  * 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.
  */
 void noFolding(String name);

 /**
  * Gets and sets the date. The value of this property will
  * reflect the 'date' header.
  */
 DateTime date;

 /**
  * Gets and sets the expiry date. The value of this property will
  * reflect the 'expires' header.
  */
 DateTime expires;

 /**
  * Gets and sets the "if-modified-since" date. The value of this property will
  * reflect the "if-modified-since" header.
  */
 DateTime ifModifiedSince;

 /**
  * Gets and sets the host part of the 'host' header for the
  * connection.
  */
 String host;

 /**
  * Gets and sets the port part of the 'host' header for the
  * connection.
  */
 int port;

 /**
  * 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.
  */
 ContentType contentType;

 /**
  * Gets and sets the content length header value.
  */
 int contentLength;

 /**
  * Gets and sets the persistent connection header value.
  */
 bool persistentConnection;

 /**
  * Gets and sets the chunked transfer encoding header value.
  */
 bool chunkedTransferEncoding;
}

Static Properties

const ACCEPT #

static const ACCEPT = "accept"

const ACCEPT_CHARSET #

static const ACCEPT_CHARSET = "accept-charset"

const ACCEPT_ENCODING #

static const ACCEPT_ENCODING = "accept-encoding"

const ACCEPT_LANGUAGE #

static const ACCEPT_LANGUAGE = "accept-language"

const ACCEPT_RANGES #

static const ACCEPT_RANGES = "accept-ranges"

const AGE #

static const AGE = "age"

const ALLOW #

static const ALLOW = "allow"

const AUTHORIZATION #

static const AUTHORIZATION = "authorization"

const CACHE_CONTROL #

static const CACHE_CONTROL = "cache-control"

const CONNECTION #

static const CONNECTION = "connection"

const CONTENT_ENCODING #

static const CONTENT_ENCODING = "content-encoding"

const CONTENT_LANGUAGE #

static const CONTENT_LANGUAGE = "content-language"

const CONTENT_LENGTH #

static const CONTENT_LENGTH = "content-length"

const CONTENT_LOCATION #

static const CONTENT_LOCATION = "content-location"

const CONTENT_MD5 #

static const CONTENT_MD5 = "content-md5"

const CONTENT_RANGE #

static const CONTENT_RANGE = "content-range"

const CONTENT_TYPE #

static const CONTENT_TYPE = "content-type"
static const COOKIE = "cookie"

const DATE #

static const DATE = "date"

const ENTITY_HEADERS #

static const ENTITY_HEADERS = const [ALLOW,
                                    CONTENT_ENCODING,
                                    CONTENT_LANGUAGE,
                                    CONTENT_LENGTH,
                                    CONTENT_LOCATION,
                                    CONTENT_MD5,
                                    CONTENT_RANGE,
                                    CONTENT_TYPE,
                                    EXPIRES,
                                    LAST_MODIFIED]

const ETAG #

static const ETAG = "etag"

const EXPECT #

static const EXPECT = "expect"

const EXPIRES #

static const EXPIRES = "expires"

const FROM #

static const FROM = "from"

const GENERAL_HEADERS #

static const GENERAL_HEADERS = const [CACHE_CONTROL,
                                     CONNECTION,
                                     DATE,
                                     PRAGMA,
                                     TRAILER,
                                     TRANSFER_ENCODING,
                                     UPGRADE,
                                     VIA,
                                     WARNING]

const HOST #

static const HOST = "host"

const IF_MATCH #

static const IF_MATCH = "if-match"

const IF_MODIFIED_SINCE #

static const IF_MODIFIED_SINCE = "if-modified-since"

const IF_NONE_MATCH #

static const IF_NONE_MATCH = "if-none-match"

const IF_RANGE #

static const IF_RANGE = "if-range"

const IF_UNMODIFIED_SINCE #

static const IF_UNMODIFIED_SINCE = "if-unmodified-since"

const LAST_MODIFIED #

static const LAST_MODIFIED = "last-modified"

const LOCATION #

static const LOCATION = "location"

const MAX_FORWARDS #

static const MAX_FORWARDS = "max-forwards"

const PRAGMA #

static const PRAGMA = "pragma"

const PROXY_AUTHENTICATE #

static const PROXY_AUTHENTICATE = "proxy-authenticate"

const PROXY_AUTHORIZATION #

static const PROXY_AUTHORIZATION = "proxy-authorization"

const RANGE #

static const RANGE = "range"

const REFERER #

static const REFERER = "referer"

const REQUEST_HEADERS #

static const REQUEST_HEADERS = const [ACCEPT,
                                     ACCEPT_CHARSET,
                                     ACCEPT_ENCODING,
                                     ACCEPT_LANGUAGE,
                                     AUTHORIZATION,
                                     EXPECT,
                                     FROM,
                                     HOST,
                                     IF_MATCH,
                                     IF_MODIFIED_SINCE,
                                     IF_NONE_MATCH,
                                     IF_RANGE,
                                     IF_UNMODIFIED_SINCE,
                                     MAX_FORWARDS,
                                     PROXY_AUTHORIZATION,
                                     RANGE,
                                     REFERER,
                                     TE,
                                     USER_AGENT]

const RESPONSE_HEADERS #

static const RESPONSE_HEADERS = const [ACCEPT_RANGES,
                                      AGE,
                                      ETAG,
                                      LOCATION,
                                      PROXY_AUTHENTICATE,
                                      RETRY_AFTER,
                                      SERVER,
                                      VARY,
                                      WWW_AUTHENTICATE]

const RETRY_AFTER #

static const RETRY_AFTER = "retry-after"

const SERVER #

static const SERVER = "server"
static const SET_COOKIE = "set-cookie"

const TE #

static const TE = "te"

const TRAILER #

static const TRAILER = "trailer"

const TRANSFER_ENCODING #

static const TRANSFER_ENCODING = "transfer-encoding"

const UPGRADE #

static const UPGRADE = "upgrade"

const USER_AGENT #

static const USER_AGENT = "user-agent"

const VARY #

static const VARY = "vary"

const VIA #

static const VIA = "via"

const WARNING #

static const WARNING = "warning"

const WWW_AUTHENTICATE #

static const WWW_AUTHENTICATE = "www-authenticate"

Properties

bool chunkedTransferEncoding #

Gets and sets the chunked transfer encoding header value.

bool chunkedTransferEncoding

int contentLength #

Gets and sets the content length header value.

int contentLength

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.

ContentType contentType

DateTime date #

Gets and sets the date. The value of this property will reflect the 'date' header.

DateTime date

DateTime expires #

Gets and sets the expiry date. The value of this property will reflect the 'expires' header.

DateTime expires

String host #

Gets and sets the host part of the 'host' header for the connection.

String host

DateTime ifModifiedSince #

Gets and sets the "if-modified-since" date. The value of this property will reflect the "if-modified-since" header.

DateTime ifModifiedSince

bool persistentConnection #

Gets and sets the persistent connection header value.

bool persistentConnection

int port #

Gets and sets the port part of the 'host' header for the connection.

int port

Operators

abstract List<String> operator [](String name) #

Returns the list of values for the header named name. If there is no header with the provided name, null will be returned.

Methods

abstract void add(String name, Object value) #

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.

abstract void forEach(void f(String name, List<String> values)) #

Enumerates the headers, applying the function f to each header. The header name passed in name will be all lower case.

abstract void noFolding(String name) #

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.

abstract void remove(String name, Object value) #

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.

abstract void removeAll(String name) #

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.

abstract void set(String name, Object value) #

Sets a header. The header named name will have all its values cleared before the value value is added as its value.

abstract String value(String name) #

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.