cookies property

Map<String, String> get cookies

Gets all cookies from the request.

Parses the Cookie header into a map of name-value pairs.

Implementation

Map<String, String> get cookies {
  final cookieHeader = header('cookie');
  if (cookieHeader == null) return {};

  return Map.fromEntries(
    cookieHeader.split(';').map((cookie) {
      final parts = cookie.trim().split('=');
      return MapEntry(
        parts[0],
        parts.length > 1 ? parts.sublist(1).join('=') : '',
      );
    }),
  );
}