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.

Parameter values can be omitted, in which case the value is parsed as null. Values can be doubled quoted to allow characters outside of the RFC 7230 token characters and backslash sequences can be used to represent the double quote and backslash characters themselves.

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.

Implementers

Constructors

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

Properties

hashCodeint
read-only, inherited
The hash code for this object. [...]
parametersMap<String, String?>
read-only
A map of parameters. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.
valueString
read-only
The value of the header.

Methods

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

Operators

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

Static Methods

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

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-io/HeaderValue-class.html