netscape-cookie-file-parser 0.1.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: 32.75 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 727.59 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s 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 preserves string-like fields as raw bytes so non-UTF-8 cookie jar data can round-trip through the parser.

use std::io::Cursor;

use netscape_cookie_file_parser::{parse, CookiePrefix};

let jar = Cursor::new(
    b"# Netscape HTTP Cookie File\n\
      .example.com\tTRUE\t/foo\tFALSE\t0\tpublic\tyes\n\
      #HttpOnly_.example.com\tTRUE\t/\tTRUE\t0\t__Secure-SID\tabc\n",
);

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

assert_eq!(cookies.len(), 2);
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);