Skip to main content

Crate netscape_cookie_file_parser

Crate netscape_cookie_file_parser 

Source
Expand description

Parser for Netscape/curl cookie jar files.

Netscape cookie files are line-oriented. Each cookie line contains seven tab-separated fields: domain, tail-match flag, path, secure flag, expires, name, and value. This crate keeps cookie data as raw bytes so non-UTF-8 cookie names, values, paths, and domains can round-trip through the parser.

Empty lines and ordinary # comments are skipped. curl’s #HttpOnly_ extension is treated as metadata on the cookie rather than as a comment.

use netscape_cookie_file_parser::{parse_line, CookiePrefix};

let cookie = parse_line("#HttpOnly_.example.com\tTRUE\t/\tTRUE\t0\t__Secure-SID\tabc")
    .unwrap()
    .unwrap();

assert_eq!(cookie.domain, b"example.com");
assert!(cookie.http_only);
assert_eq!(cookie.prefix, CookiePrefix::Secure);

Structs§

Cookie
One parsed cookie record from a Netscape cookie file.
NetscapeCookieParser
Streaming parser over a Netscape cookie file.
ParseError
Error returned when parsing a cookie stream.

Enums§

CookiePrefix
Case-sensitive cookie name prefixes recognized by the parser.
ParseErrorKind
Detailed reason a cookie line or stream could not be parsed.

Functions§

parse
Parses all valid cookie lines from a buffered reader.
parse_line
Parses one Netscape cookie file line.
parse_lossy
Parses all valid cookie lines and skips malformed cookie records.