value method
Convenience method for the value for a single valued header.
The value must not have more than one value.
Returns null
if there is no header with the provided name.
Implementation
@override
String? value(String name) {
final lcName = name.toLowerCase();
final values = _data[lcName];
if (values != null) {
if (values.isEmpty) {
return null; // unexpected: treat as if header does not exist
} else if (values.length == 1) {
return values.first;
} else {
// Multiple values not permitted for this method.
//
// This is the exception that the implementation of
// `_HttpHeaders.value`, in the Dart SDK internal "http_headers.dart"
// file, throws when there are multiple values.
throw HttpException('More than one value for header $name');
}
} else {
return null; // header does not exist
}
}