getCookies static method

String getCookies(
  1. List<Cookie> cookies
)

Merge cookies into a Cookie string. Cookies with longer paths are listed before cookies with shorter paths.

Implementation

static String getCookies(List<Cookie> cookies) {
  // Sort cookies by path (longer path first).
  cookies.sort((a, b) {
    if (a.path == null && b.path == null) {
      return 0;
    } else if (a.path == null) {
      return -1;
    } else if (b.path == null) {
      return 1;
    } else {
      return b.path!.length.compareTo(a.path!.length);
    }
  });
  return cookies.map((cookie) => '${cookie.name}=${cookie.value}').join('; ');
}