sweet_cookie_jar 1.1.0 copy "sweet_cookie_jar: ^1.1.0" to clipboard
sweet_cookie_jar: ^1.1.0 copied to clipboard

A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.

example/example.dart

// Copyright (c) 2021, Kato Shinya. All rights reserved.
// Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:http/http.dart';
import 'package:sweet_cookie_jar/sweet_cookie_jar.dart';

class DemoSweetCookieJar {
  void main() {
    final response = Response.bytes(
      [],
      200,
      headers: {
        'set-cookie':
            'AWSALB=CGSOoaFEi91n9xSfeeSxoUvs0A/TTQn9/Mbxe8dtkv50cBqJmHTwPw3; Expires=Tue, 14 Dec 2021 02:20:37 GMT; Path=/,AWSALBCORS=OHhxYMU0mU7WOoh+4RH5bxe8d6AytmnHaZNGUBqJmHTwPw3; Expires=Tue, 14 Dec 2021 02:20:37 GMT; Path=/; SameSite=None; Secure,jwt_token=test; Domain=.test; Max-Age=31536000; Path=/; expires=Wed, 07-Dec-2022 02:20:37 GMT; SameSite=lax; Secure,csrf_token=test==; Domain=.test; Max-Age=31536000; Path=/; expires=Wed, 07-Dec-2022 02:20:37 GMT,csrf_token=test==; Domain=.test; Max-Age=31536000; Path=/; expires=Wed, 07-Dec-2022 02:20:37 GMT,wuuid=77be8f46-4'
      },
    );

    final cookieJar = SweetCookieJar.from(response: response);

    if (cookieJar.isEmpty) {
      // It means that there is no cookie information
      // in the response header.
      return;
    }

    final cookie = cookieJar.find(name: 'AWSALB');
    print(cookie.name);
    print(cookie.value);
    print(cookie.toJson());

    if (cookie.isExpired) {
      // Do something
      return;
    }
  }
}
11
likes
130
pub points
76%
popularity

Publisher

verified publishershinyakato.dev

A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

collection, http, universal_io

More

Packages that depend on sweet_cookie_jar