headersSplitValues property

Map<String, List<String>> headersSplitValues

The HTTP headers returned by the server.

The header names are converted to lowercase and stored with their associated header values.

Cookies can be parsed using the dart:io Cookie class:

import "dart:io";
import "package:http/http.dart";

void main() async {
final response = await Client().get(Uri.https('example.com', '/'));
final cookies = [
  for (var value i
      in response.headersSplitValues['set-cookie'] ?? <String>[])
    Cookie.fromSetCookieValue(value)
];

Implementation

Map<String, List<String>> get headersSplitValues {
  var headersWithFieldLists = <String, List<String>>{};
  headers.forEach((key, value) {
    if (!value.contains(',')) {
      headersWithFieldLists[key] = [value];
    } else {
      if (key == 'set-cookie') {
        headersWithFieldLists[key] = value.split(_setCookieSplitter);
      } else {
        headersWithFieldLists[key] = value.split(_headerSplitter);
      }
    }
  });
  return headersWithFieldLists;
}