pub struct Cookie {
pub name: String,
pub value: String,
pub domain: String,
pub path: String,
pub expires: Option<i64>,
pub secure: bool,
pub http_only: bool,
pub same_site: String,
}Expand description
An HTTP cookie with standard browser attributes.
Fields§
§name: StringCookie name.
value: StringCookie value.
domain: StringDomain the cookie is valid for (e.g. “.github.com” for subdomains).
path: StringPath the cookie is valid for (default “/”).
expires: Option<i64>Expiration timestamp (Unix seconds). None = session cookie (but we persist anyway).
secure: boolCookie should only be sent over HTTPS.
http_only: boolCookie should not be accessible to JavaScript (browser enforcement). For agents, this is informational — we still allow access but tools should respect it when simulating browser behavior.
same_site: StringSameSite attribute: “strict”, “lax”, or “none”.
Implementations§
Source§impl Cookie
impl Cookie
Sourcepub fn new(
name: impl Into<String>,
value: impl Into<String>,
domain: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, value: impl Into<String>, domain: impl Into<String>, ) -> Self
Create a simple cookie with defaults.
Sourcepub fn matches_domain(&self, request_domain: &str) -> bool
pub fn matches_domain(&self, request_domain: &str) -> bool
Check if this cookie is valid for a given domain. Implements standard domain matching:
- Exact match: “example.com” matches “example.com”
- Subdomain match: “.example.com” matches “sub.example.com”
Sourcepub fn matches_path(&self, request_path: &str) -> bool
pub fn matches_path(&self, request_path: &str) -> bool
Check if this cookie is valid for a given path.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the cookie has expired.
Format as a Set-Cookie header value.
Format as a Cookie header value (just name=value).