Cookie and Set-Cookie parser and serializer.
To install ocookie add the following to your pubspec.yaml
dependencies:
ocookie: latestAlternatively, you can run the following command:
dart pub add ocookiefinal cookie = Cookie('name', 'value');
print(cookie.serialize()); // name=value
print(Cookie.parse('a=b;b=c')); // {a: b, b: c}
final setCookie = Cookie.fromString(
'sid=abc; Path=/; HttpOnly; Secure; SameSite=None',
);
print(setCookie.path); // /
final values = Cookie.splitSetCookie(
'a=b; Expires=Wed, 21 Oct 2015 07:28:00 GMT, c=d; Path=/',
);
print(values); // [a=b; Expires=Wed, 21 Oct 2015 07:28:00 GMT, c=d; Path=/]Cookie.serialize- Serialize a cookie instance to string.Cookie.validate- Validate a cookie and return all errors.Cookie.parse- Parse client-sidecookieheader map.Cookie.fromString- Parse a set-cookie string to Cookie instance.Cookie.splitSetCookie- Split a string of multiple set-cookie values into a set-cookie string list.
final original = Cookie(
'sid',
'abc',
path: '/demo',
secure: true,
sameSite: CookieSameSite.none,
);
final updated = original.copyWith(path: '/next');
final cleared = original.copyWith(
clear: {CookieNullableField.path},
);final cookie = Cookie(
'sid',
'abc',
sameSite: CookieSameSite.none,
);
final errors = cookie.validate();
if (errors.isNotEmpty) {
print(errors);
}SameSite=NonerequiresSecure=true.Partitioned=truerequiresSecure=true.
See the API documentation for detailed information about all available APIs.