1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! 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);
//! ```
use BufRead;
pub use ;
pub use ;
pub use NetscapeCookieParser;
/// Parses all valid cookie lines from a buffered reader.
///
/// The first malformed cookie line or I/O error stops parsing and returns a
/// [`ParseError`] with the 1-based line number.
/// Parses all valid cookie lines and skips malformed cookie records.
///
/// I/O errors are still returned because the parser cannot safely continue once
/// the underlying reader fails.
/// Parses one Netscape cookie file line.
///
/// Returns `Ok(None)` for blank lines, ordinary comments, and `#HttpOnly_`
/// lines whose payload is still a comment.