pub struct CookieConfig { /* private fields */ }Expand description
Session cookie attributes.
The defaults are the safest option for a same-origin app:
Set-Cookie: __Host-sid=<43 chars>; Path=/; Max-Age=2592000; HttpOnly; Secure; SameSite=LaxBrowsers enforce the __Host- prefix: the cookie must be Secure, have Path=/ and no
Domain, so a sibling subdomain cannot set or overwrite it. CookieConfig::validate (run by
GuardConfig’s build) rejects combinations browsers would drop.
Implementations§
Source§impl CookieConfig
impl CookieConfig
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Cookie name. Keep the __Host- prefix unless you need Domain or a narrower Path.
Sourcepub fn domain(self, domain: impl Into<String>) -> Self
pub fn domain(self, domain: impl Into<String>) -> Self
Domain attribute (default none, i.e. host-only). Not allowed with __Host-.
Sourcepub const fn secure(self, secure: bool) -> Self
pub const fn secure(self, secure: bool) -> Self
Secure attribute (default on). Only turn this off for plain-HTTP local development, and
then also drop the __Host- prefix.
Sourcepub const fn http_only(self, http_only: bool) -> Self
pub const fn http_only(self, http_only: bool) -> Self
HttpOnly attribute (default on), which hides the token from JavaScript.
Sourcepub const fn persistent(self, persistent: bool) -> Self
pub const fn persistent(self, persistent: bool) -> Self
Whether the cookie carries Max-Age (default on). When off, it is a browser-session
cookie that disappears when the browser closes; server-side expiry still applies.
The cookie name.
Sourcepub fn validate(&self) -> Result<(), ConfigError>
pub fn validate(&self) -> Result<(), ConfigError>
Checks the attributes against what browsers accept.
§Errors
ConfigError::InvalidCookie describing the first problem found.
Renders a Set-Cookie value carrying token. max_age_secs is clamped at zero and only
emitted for persistent cookies.
Renders a Set-Cookie value that deletes the cookie.
Trait Implementations§
Source§impl Clone for CookieConfig
impl Clone for CookieConfig
Source§impl Debug for CookieConfig
impl Debug for CookieConfig
Source§impl Default for CookieConfig
impl Default for CookieConfig
impl Eq for CookieConfig
Source§impl PartialEq for CookieConfig
impl PartialEq for CookieConfig
impl StructuralPartialEq for CookieConfig
Auto Trait Implementations§
impl Freeze for CookieConfig
impl RefUnwindSafe for CookieConfig
impl Send for CookieConfig
impl Sync for CookieConfig
impl Unpin for CookieConfig
impl UnsafeUnpin for CookieConfig
impl UnwindSafe for CookieConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more