parseCookies function

Map<String, String> parseCookies(
  1. String cookieString
)

Parses a cookie string to a map.

Implementation

Map<String, String> parseCookies(String cookieString) {
  List<String> cookieList = cookieString.split('; ');

  Map<String, String> cookies = {};

  for (String cookie in cookieList) {
    List<String> cookieParts = cookie.split('=');
    if (cookieParts.length == 2) {
      String name = cookieParts[0];
      String value = cookieParts[1];
      cookies[name] = value;
    }
  }

  return cookies;
}