copyWithRaw method

HttpHeaders copyWithRaw({
  1. required String name,
  2. required String value,
})

Adds a header to the headers. Returns a new instance of HttpHeaders with the added header. Converts HttpHeaderMap to HttpHeaderRawMap.

Implementation

HttpHeaders copyWithRaw({required String name, required String value}) {
  return switch (this) {
    HttpHeaderMap map => HttpHeaders.rawMap({
        for (final entry in map.map.entries) entry.key.httpName: entry.value,
        name: value,
      }),
    HttpHeaderRawMap rawMap => HttpHeaders.rawMap({
        ...rawMap.map,
        name: value,
      }),
    HttpHeaderList list => HttpHeaders.list([
        ...list.list,
        (name, value),
      ]),
  };
}