headerRemove method

bool headerRemove(
  1. String name, [
  2. String? value
])

Removes named header

If no value is provided, removes all headers matching the name. That is, the header's value is ignored; and multiple headers are removed if there are more than one header with the name.

If a value is provided, removes the first header that matches the name and has that value. If there are multiple headers for the name, those with other values or the other headers with the same value are not removed.

Returns false if there was nothing to remove. Otherwise, true is returned.

The name is case-insensitive. The name is considered the same, whether it is represented using uppercase or lowercase letters.

Implementation

bool headerRemove(String name, [String? value]) {
  final canonicalName = _headerCanonicalName(name);

  final _values = _headers[canonicalName];
  if (_values != null) {
    if (value == null) {
      // Remove all headers, regardless of their value(s)
      _headers.remove(canonicalName);
      return true;
    } else {
      // Only remove the first header with a matching value, if there is any.
      return _values.remove(value);
    }
  } else {
    // Name does not exist
    return false;
  }
}