store method
Implementation
void store(Uri uri, Iterable<String> values) {
for (final value in values) {
Cookie cookie;
try {
cookie = Cookie.fromSetCookieValue(value);
} on FormatException {
continue;
}
final domain =
cookie.domain?.replaceFirst(RegExp(r'^\.'), '').toLowerCase();
if (domain != null && domain != uri.host.toLowerCase()) continue;
if (cookie.secure && uri.scheme != 'https') continue;
var path = cookie.path;
if (path == null || !path.startsWith('/')) {
final slash = uri.path.lastIndexOf('/');
path = slash <= 0 ? '/' : uri.path.substring(0, slash);
}
if (cookie.name.startsWith('__Secure-') &&
(!cookie.secure || uri.scheme != 'https')) {
continue;
}
if (cookie.name.startsWith('__Host-') &&
(!cookie.secure || cookie.domain != null || path != '/')) {
continue;
}
final key = '${uri.host}|$path|${cookie.name}';
final expires = cookie.maxAge != null
? _clock().add(Duration(seconds: cookie.maxAge!))
: cookie.expires;
if (expires != null && !expires.isAfter(_clock())) {
_cookies.remove(key);
continue;
}
_cookies[key] = StoredCookie(
cookie: cookie, host: uri.host, path: path, expires: expires);
}
}