pub struct JarCookie {
pub name: String,
pub value: String,
pub domain: String,
pub path: String,
pub expires: Option<SystemTime>,
pub secure: bool,
pub http_only: bool,
pub creation_time: SystemTime,
}Expand description
An enhanced cookie representation using SystemTime for expiration tracking.
This struct provides URL-based matching, Set-Cookie header parsing,
and serialization. It is designed to work alongside the existing Cookie
from cookie.rs while adding SystemTime-based expiration and simpler
URL-based matching.
Fields§
§name: StringCookie name
value: StringCookie value
domain: StringDomain this cookie belongs to (e.g., “example.com”)
path: StringPath scope (usually “/”)
expires: Option<SystemTime>Expiration time; None means session cookie (no persistent expiry)
secure: boolOnly send over HTTPS connections
http_only: boolNot accessible to JavaScript (client-side only)
creation_time: SystemTimeWhen this cookie was created
Implementations§
Source§impl JarCookie
impl JarCookie
Sourcepub fn new(name: &str, value: &str, domain: &str) -> Self
pub fn new(name: &str, value: &str, domain: &str) -> Self
Create a new basic session cookie.
§Arguments
name- Cookie namevalue- Cookie valuedomain- Domain the cookie belongs to
Sourcepub fn matches_url(&self, url: &str, is_secure: bool) -> bool
pub fn matches_url(&self, url: &str, is_secure: bool) -> bool
Check whether this cookie should be sent for the given URL.
Matching rules:
- Secure cookies are only sent over HTTPS (
is_secure = true) - The URL must contain the cookie’s domain
- The URL must match the cookie’s path scope
- The cookie must not have expired
§Arguments
url- The request URL string to match againstis_secure- Whether the connection uses HTTPS
§Returns
true if this cookie should be included in requests to the given URL.
Sourcepub fn to_header_value(&self) -> String
pub fn to_header_value(&self) -> String
Format this cookie as a Set-Cookie header value string.
Produces output like: name=value; Domain=example.com; Path=/
Parse a cookie from a Set-Cookie response header value.
Supports standard attributes:
Domain=- cookie domain scopePath=- cookie path scopeExpires=- expiration timestamp (RFC 7231 / RFC 850 / asctime formats)Secure- HTTPS-only flagHttpOnly- JavaScript-inaccessible flagMax-Age=- relative expiration in seconds
§Arguments
header_value- The raw Set-Cookie header value string
§Returns
Some(JarCookie) on successful parse, None if the header is malformed.
§Example
use aria2_core::http::cookie_storage::JarCookie;
let cookie = JarCookie::parse_set_cookie(
"session=abc123; Domain=example.com; Path=/; Secure; HttpOnly"
).unwrap();
assert_eq!(cookie.name, "session");
assert_eq!(cookie.domain, "example.com");
assert!(cookie.secure);
assert!(cookie.http_only);