Dart API Referencedart:ioHeaderValue

HeaderValue abstract class

Representation of a header value in the form:

value; parameter1=value1; parameter2=value2

HeaderValue can be used to conveniently build and parse header values on this form.

To build an accepts header with the value

text/plain; q=0.3, text/html

use code like this:

HttpClientRequest request = ...;
var v = new HeaderValue("text/plain", {"q": "0.3"});
request.headers.add(HttpHeaders.ACCEPT, v);
request.headers.add(HttpHeaders.ACCEPT, "text/html");

To parse the header values use the parse static method.

HttpRequest request = ...;
List<String> values = request.headers[HttpHeaders.ACCEPT];
values.forEach((value) {
  HeaderValue v = HeaderValue.parse(value);
  // Use v.value and v.parameters
});

An instance of HeaderValue is immutable.

abstract class HeaderValue {
 /**
  * Creates a new header value object setting the value part.
  */
 factory HeaderValue([String value = "", Map<String, String> parameters]) {
   return new _HeaderValue(value, parameters);
 }

 /**
  * Creates a new header value object from parsing a header value
  * string with both value and optional parameters.
  */
 static HeaderValue parse(String value,
                          {String parameterSeparator: ";"}) {
   return _HeaderValue.parse(value, parameterSeparator: parameterSeparator);
 }

 /**
  * Gets the header value.
  */
 String get value;

 /**
  * Gets the map of parameters.
  */
 Map<String, String> get parameters;

 /**
  * Returns the formatted string representation in the form:
  *
  *     value; parameter1=value1; parameter2=value2
  */
 String toString();
}

Subclasses

ContentType

Static Methods

HeaderValue parse(String value, {String parameterSeparator: ";"}) #

Creates a new header value object from parsing a header value string with both value and optional parameters.

static HeaderValue parse(String value,
                        {String parameterSeparator: ";"}) {
 return _HeaderValue.parse(value, parameterSeparator: parameterSeparator);
}

Constructors

factory HeaderValue([String value = "", Map<String, String> parameters]) #

Creates a new header value object setting the value part.

factory HeaderValue([String value = "", Map<String, String> parameters]) {
 return new _HeaderValue(value, parameters);
}

Properties

final Map<String, String> parameters #

Gets the map of parameters.

Map<String, String> get parameters;

final String value #

Gets the header value.

String get value;

Methods

abstract String toString() #

Returns the formatted string representation in the form:

value; parameter1=value1; parameter2=value2