pub repository
mirror.p-hatan.comcookie_jar
0.0.1A cookie manager for http requests in Dart, by which you can deal with the complex cookie policy and persist cookies easily.
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.com
flutter pub add cookie_jarpubspec.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
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2018-04-26T10:09:09.764531Z | Download | 7e06aaa8e606a8ad4ad3b6885197f2935bb19a0cdb4c32944fc16131e816fd9c |
| 0.0.2 | 2018-04-26T10:31:31.557650Z | Download | 732e36e6b192bb19cafab3247c7ddba6e5855faf5cc7315b5028736ca4f05e35 |
| 0.0.3 | 2018-04-27T08:03:23.511763Z | Download | bc2e43f4ec7628b7cb00d9b11b9d59d3fcb59f74fb42642e04d5978dc71df818 |
| 0.0.4 | 2018-05-23T08:47:24.984719Z | Download | 87f64b1b6641fb5f1876d9fb8c17dbadf4aa2eda0b533879c49181c0d668acc6 |
| 0.0.5 | 2018-08-20T02:23:42.893373Z | Download | 18a3c99e333bbd4b8ec562a5ac9e261091b53e6a9aa764f3aecc11dcf76dc57d |
| 0.0.6 | 2018-08-20T03:21:09.413154Z | Download | 8f7fe31841b3d3e5980b5ec9b72b4d06f5b44e2ba4f37ce183a106afdb2262b3 |
| 0.0.7 | 2018-11-19T06:40:45.758239Z | Download | a03926fa0700bbddbb8a75409d193ce42e3f44be4ab48a0973fa822151ba0a99 |
| 0.0.8 | 2019-02-17T13:32:22.168709Z | Download | 0a76affc41632e8b2409d1730e231422895c930d349ce21dd44f1ef8e4555eba |
| 1.0.0 | 2019-02-18T07:23:23.324486Z | Download | c11415c0c8cbadec72269019b2269f50770b2233d3ffdc5c4bdd3c9067998944 |
| 1.0.1 | 2019-07-02T10:53:33.378918Z | Download | eede1c99d75847599b08911f680beb29e2b52aafad9a81271207f4dd8b0d31e0 |
| 2.0.0-nullsafety | 2021-02-22T13:27:31.218644Z | Download | ecca4ac2d82978fd17f73ec1dc5df3593b5177821290f6d7951b7977a303856f |
| 2.0.0 | 2021-02-22T13:36:11.576665Z | Download | 6a70766dbec044718f1ac82a47afd8dc94a3e64b8415c1c898781b82f43bf485 |
| 3.0.0-beta1 | 2021-02-28T09:30:26.112595Z | Download | b59f13022b7e62cc66e170c56d16ca6e2dbb6eb33d9368c8ed69887d96bd91af |
| 3.0.0-beta2 | 2021-03-01T09:32:39.734231Z | Download | 6bc2af0e9399662d7caa80b79c936c1f80a88fe4dca09df5dd21e1e3dc7e9694 |
| 3.0.0 | 2021-03-28T11:42:10.686898Z | Download | 38453776bb7544c59820196ee6fb29119be7eace2271d20d241e6517de2d9a13 |
| 3.0.1-prev1 | 2021-03-31T08:55:13.339230Z | Download | 8b22e88846cf111baff58241fd024aa89992955ec9a0bb4e6994eb0093031d0d |
| 3.0.1 | 2021-04-01T03:10:14.892021Z | Download | d1cc6516a190ba667941f722b6365d202caff3dacb38de24268b8d6ff1ec8a1d |
| 4.0.0 | 2023-03-22T03:38:31.158358Z | Download | a0be140b090d7458f8bfd4e821d97b8c4692177f3dd2981a47187fe1495c459e |
| 4.0.1-beta | 2023-02-24T08:09:50.849744Z | Download | 985d5e483b74b87b12261a777dd2becb104a9267ab9258edf2da15bccae51fe1 |
| 4.0.1 | 2023-03-24T05:50:28.555787Z | Download | 253920541bf248e4eda6eac5df6aa00c19c183e1fe333629925d8df666a27815 |
| 4.0.2 | 2023-04-30T05:33:39.956318Z | Download | 700cda09e47e90c749a3bcaf6daef3cdef4eca246db63eceabceeb29cef93bcc |
| 4.0.3 | 2023-06-01T04:26:04.801190Z | Download | 823fd13d22c5cf0c846e8a31c9b276f768f423cca134990c22c33045462f8ef9 |
| 4.0.4 | 2023-06-16T04:22:19.429853Z | Download | b1755208c3faff43408c5df116e185b93b6afe977d2c7f99e524979d98c4bf36 |
| 4.0.5 | 2023-06-16T15:16:14.968099Z | Download | 1024f3a52bee181fc8f10f4a359085471587d7406323090a53a7171bc0aa5c37 |
| 4.0.6 | 2023-07-18T03:07:37.957977Z | Download | 03be5ec8693f481a7cd8f25bca196e101872d3ced2cdbcf2d402c1c871023c44 |
| 4.0.7 | 2023-07-18T04:34:27.764505Z | Download | 7528474d59580b102b27eb0db992b878b8c515d7b18881d5711498ad6ebc1b67 |
| 4.0.8 | 2023-07-22T20:31:29.766486Z | Download | a6ac027d3ed6ed756bfce8f3ff60cb479e266f3b0fdabd6242b804b6765e52de |
| 4.0.9 | 2026-02-27T15:36:18.001514Z | Download | 963da02c1ef64cb5ac20de948c9e5940aa351f1e34a12b1d327c83d85b7e8fff |
Dependencies
No direct dependencies declared.