Viewing version 0.0.1. Open the latest package page.

cookie_jar

0.0.1

A cookie manager for http requests in Dart, by which you can deal with the complex cookie policy and persist cookies easily.

Download archive

Readme

CookieJar

build statud Pub coverage support

A cookie manager for http requests in Dart, by which you can deal with the complex cookie policy and persist cookies easily.

Add dependency

dependencies:
  dio: ^0.0.1

Usage

A simple usage example:

import 'package:cookie_jar/cookie_jar.dart';
void main() async {
  List<Cookie> cookies = [
    new Cookie("name", "wendux")
    new Cookie("location", "china")
  ];
    
  var cj = new DefaultCookieJar();
  cj.saveFromResponse(Uri.parse("https://www.baidu.com/"), cookies);
  List<Cookie> results = cj.loadForRequest(Uri.parse("https://www.baidu.com/xx"));
  print(results);  
}    
       

Classes

DefaultCookieJar

DefaultCookieJar is a default cookie manager which implements the standard cookie policy declared in RFC. DefaultCookieJar saves the cookies in RAM, so if the application exit, all cookies will be cleared.

PersistCookieJar

PersistCookieJar is a cookie manager which implements the standard cookie policy declared in RFC. PersistCookieJar persists the cookies in files, so if the application exit, the cookies always exist unless call delete explicitly.

SerializableCookie

This class is a wrapper for Cookie class. Because the Cookie class doesn't support Json serialization, for the sake of persistence, we use this class instead of it.

APIs

void saveFromResponse(Uri uri, List cookies);

Save the cookies for specified uri.

List loadForRequest(Uri uri);

Load the cookies for specified uri.

delete(Uri uri,[bool withDomainSharedCookie = false] )

Delete cookies for specified uri. This API will delete all cookies for the uri.host, it will ignored the uri.path.

If withDomainSharedCookie is true , will delete the domain-shared cookies.

Note: This API is only available in PersistCookieJar class.

Working with HttpClient

Using DefaultCookieJar or PersistCookieJar manages HttpClient 's request/response cookies is very easy:

var cj=new DefaultCookieJar();
...
request= await httpClient.openUrl(options.method, uri);
request.cookies.addAll(cj.loadForRequest(uri));
response= await request.close();
cj.saveFromResponse(uri, response.cookies);

Working with dio

dio is a powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, File downloading, Timeout etc. And dio supports to manage cookies with cookie_jar, the simple example is:

var dio = new Dio();
dio.cookieJar=new PersistCookieJar("./cookies");
Response<String>  response = await dio.get("https://www.baidu.com");

More details about dio see : https://github.com/flutterchina/dio .

Copyright & License

This open source project authorized by https://flutterchina.club , and the license is MIT.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.0.1

  • Initial version, created by Stagehand

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'cookie_jar:0.0.1'
pubspec.yaml
name: cookie_jar
description: A cookie manager for http requests in Dart, by which you can deal with the complex cookie policy and persist cookies easily.
version: 0.0.1
homepage: https://github.com/flutterchina/cookie_jar
author: wendux <824783146@qq.com>

environment:
  sdk: '>=1.20.1 <2.0.0'

#dependencies:
#  path: ^1.4.1

dev_dependencies:
  test: ^0.12.0
  coverage: "^0.9.3"
  dart_codecov_generator:
    git:
      url: "https://github.com/wendux/dart-codecov.git"

Version history

VersionPublishedArchiveSHA-256
0.0.1Cached · Upstream SHA-256 matchedDownload7e06aaa8…16fd9c
0.0.2Cached · Upstream SHA-256 matchedDownload732e36e6…f05e35
0.0.3Cached · Upstream SHA-256 matchedDownloadbc2e43f4…1df818
0.0.4Cached · Upstream SHA-256 matchedDownload87f64b1b…68acc6
0.0.5Cached · Upstream SHA-256 matchedDownload18a3c99e…6dc57d
0.0.6Cached · Upstream SHA-256 matchedDownload8f7fe318…2262b3
0.0.7Cached · Upstream SHA-256 matchedDownloada03926fa…ba0a99
0.0.8Cached · Upstream SHA-256 matchedDownload0a76affc…555eba
1.0.0Cached · Upstream SHA-256 matchedDownloadc11415c0…998944
1.0.1Cached · Upstream SHA-256 matchedDownloadeede1c99…0d31e0
2.0.0-nullsafetyCached · Upstream SHA-256 matchedDownloadecca4ac2…03856f
2.0.0Cached · Upstream SHA-256 matchedDownload6a70766d…3bf485
3.0.0-beta1Cached · Upstream SHA-256 matchedDownloadb59f1302…bd91af
3.0.0-beta2Cached · Upstream SHA-256 matchedDownload6bc2af0e…7e9694
3.0.0Cached · Upstream SHA-256 matchedDownload38453776…2d9a13
3.0.1-prev1Cached · Upstream SHA-256 matchedDownload8b22e888…031d0d
3.0.1Cached · Upstream SHA-256 matchedDownloadd1cc6516…ec8a1d
4.0.0Cached · Upstream SHA-256 matchedDownloada0be140b…5c459e
4.0.1-betaCached · Upstream SHA-256 matchedDownload985d5e48…e51fe1
4.0.1Cached · Upstream SHA-256 matchedDownload25392054…a27815
4.0.2Cached · Upstream SHA-256 matchedDownload700cda09…f93bcc
4.0.3Cached · Upstream SHA-256 matchedDownload823fd13d…2f8ef9
4.0.4Cached · Upstream SHA-256 matchedDownloadb1755208…c4bf36
4.0.5Cached · Upstream SHA-256 matchedDownload1024f3a5…aa5c37
4.0.6Cached · Upstream SHA-256 matchedDownload03be5ec8…023c44
4.0.7Cached · Upstream SHA-256 matchedDownload7528474d…bc1b67
4.0.8Cached · Upstream SHA-256 matchedDownloada6ac027d…5e52de
4.0.9Cached · Upstream SHA-256 matchedDownload963da02c…7e8fff

Dependencies

No direct dependencies declared.