http_cookie_parser 1.0.0+1 copy "http_cookie_parser: ^1.0.0+1" to clipboard
http_cookie_parser: ^1.0.0+1 copied to clipboard

retracted

Parser that reads and splits the set-cookie comma joined value into actual separate cookies.

Parser for the comma joined set-header cookie header that the http package gives back. The CookieParser will accept that singular header value and then attempt to parse it back into the original separated values.

Usage #

import 'package:http/http.dart' as http;
import 'package:http_cookie_parser/http_cookie_parser.dart';

Future<void> load() async {
  final response = await http.get('https://www.cnn.com'); // CNN is known to have troublesome cookies
  final cookies = CookieParser(response.headers['set-cookie']).cookies;

  // Now you can do whatever you need as each element in the cookies array is an
  // individual cookie value again.
}

Why is this necessary? #

Cookie values can contain commas within them. In fact, the Expires value is spec'd to have one in it. Let's say you get back the cookies from the server:

set-cookie: foo=bar; Expires=Expires=Fri, 20 Aug 2027 00:55:08 GMT
set-cookie: commas=a,b,c,d; HttpOnly

Then what you will get back from the http package when you query the set-cookie header is actually:

foo=bar; Expires=Expires=Fri, 20 Aug 2027 00:55:08 GMT,commas=a,b,c,d; HttpOnly

Try to do a value.split(',') and you get:

[
  'foo=bar; Expires=Expires=Fri',
  '20 Aug 2027 00:55:08 GMT',
  'commas=a',
  'b',
  'c',
  'd; HttpOnly'
]

Try to parse those items using any standard cookie decoder and you're toing to get a parse error.

0
likes
0
points
29
downloads

Publisher

verified publisherilt.run

Weekly Downloads

Parser that reads and splits the set-cookie comma joined value into actual separate cookies.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on http_cookie_parser