copyWithout method

HttpHeaders copyWithout(
  1. HttpHeaderName key
)

Removes a header from the headers. Returns a new instance of HttpHeaders without the key.

Implementation

HttpHeaders copyWithout(HttpHeaderName key) {
  return switch (this) {
    HttpHeaderMap map => HttpHeaders.map({
        for (final entry in map.map.entries)
          if (entry.key != key) entry.key: entry.value,
      }),
    HttpHeaderRawMap rawMap => HttpHeaders.rawMap({
        for (final entry in rawMap.map.entries)
          if (entry.key.toLowerCase() != key.httpName) entry.key: entry.value,
      }),
    HttpHeaderList list => HttpHeaders.list([
        for (final entry in list.list)
          if (entry.$1.toLowerCase() != key.httpName) entry,
      ]),
  };
}