Dart API Referencedart:ioHttpHeaders

HttpHeaders abstract class

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

For all operation 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";

  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 headers with the provided name [:null:] will be returned.
   */
  List<String> operator[](String name);

  /**
   * Convenience method for the value for a single values 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
   * values and for these adding a value will replace the previous
   * value. If the value is of type Date 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);

  /**
   * Remove 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);

  /**
   * Enumerate 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));

  /**
   * Disable 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.
   */
  Date date;

  /**
   * Gets and sets the expiry date. The value of this property will
   * reflect the "Expires" header.
   */
  Date expires;

  /**
   * Gets and sets the 'if-modified-since' date. The value of this property will
   * reflect the "if-modified-since" header.
   */
  Date 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;
}

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";

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";

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

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;

Date date #

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

Date date;

Date expires #

Gets and sets the expiry date. The value of this property will reflect the "Expires" header.

Date expires;

String host #

Gets and sets the host part of the "Host" header for the connection.

String host;

Date ifModifiedSince #

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

Date ifModifiedSince;

int port #

Gets and sets the port part of the "Host" header for the connection.

int port;

Operators

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

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

List<String> operator[](String name);

Methods

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 values and for these adding a value will replace the previous value. If the value is of type Date 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);

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

Enumerate 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));

void noFolding(String name) #

Disable 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);

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.

void remove(String name, Object value);

void removeAll(String name) #

Remove 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);

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.

void set(String name, Object value);

String value(String name) #

Convenience method for the value for a single values 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);