Expand description
§set-cookie-parser — parse Set-Cookie response headers
Parse a Set-Cookie header value into a structured Cookie, and split a
comma-joined Set-Cookie string into individual cookies without choking on the
commas inside an Expires date. A faithful Rust port of the
set-cookie-parser npm package.
Zero dependencies and #![no_std].
use set_cookie_parser::{parse, parse_all, split_cookies_string};
let c = parse("sid=abc123; Path=/; HttpOnly; SameSite=Lax").unwrap();
assert_eq!(c.name, "sid");
assert_eq!(c.value, "abc123");
assert_eq!(c.path.as_deref(), Some("/"));
assert!(c.http_only);
assert_eq!(c.same_site.as_deref(), Some("Lax"));
// A single combined header with two cookies (note the comma inside Expires):
let header = "a=1; Expires=Wed, 09 Jun 2021 10:18:14 GMT, b=2";
assert_eq!(split_cookies_string(header), ["a=1; Expires=Wed, 09 Jun 2021 10:18:14 GMT", "b=2"]);
assert_eq!(parse_all(header).len(), 2);Structs§
- Cookie
- A parsed cookie from a
Set-Cookieheader.
Functions§
- parse
- Parse a single
Set-Cookieheader value into aCookie, URI-decoding the value. - parse_
all - Split a combined
Set-Cookieheader and parse each cookie (URI-decoding values). - parse_
all_ with - Split a combined
Set-Cookieheader and parse each cookie, controlling URI-decoding. - parse_
with - Parse a single
Set-Cookieheader value, controlling whether the cookie value is URI-decoded (decodeURIComponent). On a decode error the raw value is kept. - split_
cookies_ string - Split a combined
Set-Cookieheader string into individual cookie strings.