Expand description
HTTP cookie parsing and cookie jar management.
This crates provides the Cookie type, representing an HTTP cookie, and
the CookieJar type, which manages a collection of cookies for session
management, recording changes as they are made, and optional automatic
cookie encryption and signing.
§Usage
Add the following to the [dependencies] section of your Cargo.toml:
cookie = "0.18"§Features
This crate exposes several features, all of which are disabled by default:
-
percent-encodeEnables percent encoding and decoding of names and values in cookies.
When this feature is enabled, the
Cookie::encoded()andCookie::parse_encoded()methods are available. Theencodedmethod returns a wrapper around aCookiewhoseDisplayimplementation percent-encodes the name and value of the cookie. Theparse_encodedmethod percent-decodes the name and value of aCookieduring parsing. -
signedEnables signed cookies via [
CookieJar::signed()].When this feature is enabled, the [
CookieJar::signed()] method, [SignedJar] type, and [Key] type are available. The jar acts as “child jar”; operations on the jar automatically sign and verify cookies as they are added and retrieved from the parent jar. -
privateEnables private (authenticated, encrypted) cookies via [
CookieJar::private()].When this feature is enabled, the [
CookieJar::private()] method, [PrivateJar] type, and [Key] type are available. The jar acts as “child jar”; operations on the jar automatically encrypt and decrypt/authenticate cookies as they are added and retrieved from the parent jar. -
key-expansionEnables key expansion or key derivation via [
Key::derive_from()].When this feature is enabled, and either
signedorprivateare also enabled, the [Key::derive_from()] method is available. The method can be used to derive aKeystructure appropriate for use with signed and private jars from cryptographically valid key material that is shorter in length than the full key. -
secureA meta-feature that simultaneously enables
signed,private, andkey-expansion.
You can enable features via Cargo.toml:
[dependencies.cookie]
features = ["secure", "percent-encode"]Re-exports§
pub use time;
Modules§
- prefix
- Implementation of HTTP RFC6265 draft cookie prefixes.
Structs§
- Cookie
- Representation of an HTTP cookie.
- Cookie
Builder - Structure that follows the builder pattern for building
Cookiestructs. - Cookie
Jar - A collection of cookies that tracks its modifications.
- Delta
- Iterator over the changes to a cookie jar.
- Display
- Wrapper around
CookiewhoseDisplayimplementation either percent-encodes the cookie’s name and value, skips displaying the cookie’s parameters (only displaying it’s name and value), or both. - Iter
- Iterator over all of the cookies in a jar.
- Split
Cookies - An iterator over cookie parse
Results:Result<Cookie, ParseError>.
Enums§
- Expiration
- A cookie’s expiration: either a date-time or session.
- Parse
Error - Enum corresponding to a parsing error.
- Same
Site - The
SameSitecookie attribute.