netscape-cookie-file-parser 0.3.0

Parse Netscape/curl cookie jar files while preserving raw cookie bytes.
Documentation
  • Coverage
  • 96.43%
    27 out of 28 items documented1 out of 4 items with examples
  • Size
  • Source code size: 40.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 726.58 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ldm0/netscape-cookie-file-parser
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ldm0

netscape-cookie-file-parser

Parser for Netscape/curl cookie jar files.

Netscape cookie files are line-oriented and store seven tab-separated fields: domain, tail-match flag, path, secure flag, expires, name, and value. This crate keeps string-like fields as byte buffers so non-UTF-8 cookie jar data can be represented without UTF-8 conversion.

By default, parse removes one leading dot from the domain field, accepts curl's legacy missing-path records with / as the path, and preserves ordinary path fields as they appear in the file.

use std::io::Cursor;

use netscape_cookie_file_parser::{parse, CookiePrefix};

let jar = Cursor::new(br#"
# Netscape HTTP Cookie File
.example.com	TRUE	/foo	FALSE	0	public	yes
#HttpOnly_.example.com	TRUE	/	TRUE	0	__Secure-SID	abc
"#);

let cookies = parse(jar).unwrap();

assert_eq!(cookies.len(), 2);
assert_eq!(cookies[0].domain, b"example.com");
assert_eq!(cookies[0].name, b"public");
assert_eq!(cookies[0].path, b"/foo");
assert!(cookies[1].http_only);
assert_eq!(cookies[1].prefix, CookiePrefix::Secure);