pub struct CookiePolicy { /* private fields */ }Expand description
Policy governing cookie construction (RFC-006 §4).
Build with CookiePolicy::production_strict for the standard profile,
or use the builder methods to customise. HttpOnly=true cannot be disabled
(RFC-006 §13.2: “A production profile should reject Secure=false”).
Implementations§
Source§impl CookiePolicy
impl CookiePolicy
Sourcepub fn production_strict(name: impl Into<String>, max_age: Duration) -> Self
pub fn production_strict(name: impl Into<String>, max_age: Duration) -> Self
Standard production policy: HttpOnly; Secure; SameSite=Strict; Path=/.
Domain is omitted to produce a host-only cookie (RFC-006 §5,
implementation note: omitting Domain avoids subdomain leakage).
Sourcepub fn production_lax(name: impl Into<String>, max_age: Duration) -> Self
pub fn production_lax(name: impl Into<String>, max_age: Duration) -> Self
Production policy with SameSite=Lax for cross-site top-level flows.
Sourcepub fn local_development(name: impl Into<String>, max_age: Duration) -> Self
pub fn local_development(name: impl Into<String>, max_age: Duration) -> Self
Development-only policy: Secure=false; SameSite=Lax. The caller must
document why this is acceptable; it must not be used in production.
Sourcepub fn with_domain(self, domain: Option<impl Into<String>>) -> Self
pub fn with_domain(self, domain: Option<impl Into<String>>) -> Self
Set an explicit Domain attribute. Pass None to produce a host-only
cookie (the default and recommended choice).
Sourcepub fn max_age_duration(&self) -> Duration
pub fn max_age_duration(&self) -> Duration
The configured max-age as a Duration.
Build a Set-Cookie header value that delivers secret to the client.
secret must be the plaintext session or token secret — the only
moment it crosses the wire. The caller must not log the returned string.
Build a Set-Cookie header value that clears this cookie (e.g. logout).
Uses Max-Age=0 with the same path/domain/name so browsers delete the
existing cookie (RFC-006 §4 “clear cookie helper mirrors path/domain/name”).