HeaderValue 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.acceptHeader, v);
request.headers.add(HttpHeaders.acceptHeader, "text/html");

To parse the header values use the parse static method.

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

An instance of HeaderValue is immutable.

Implemented by

Constructors

HeaderValue([String value = "", Map<String, String> parameters ])
Creates a new header value object setting the value and parameters.
factory

Properties

parameters Map<String, String>
Gets the map of parameters. [...]
read-only
value String
Gets the header value.
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

toString() String
Returns the formatted string representation in the form: [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Methods

parse(String value, { String parameterSeparator: ";", String valueSeparator: null, bool preserveBackslash: false }) HeaderValue
Creates a new header value object from parsing a header value string with both value and optional parameters.