Struct tower_sessions::CookieConfig
source · pub struct CookieConfig {
pub name: String,
pub same_site: SameSite,
pub max_age: Option<Duration>,
pub secure: bool,
pub path: String,
pub domain: Option<String>,
}Expand description
Defines the configuration for the cookie belonging to the session.
Fields§
§name: StringThe name of the cookie.
same_site: SameSiteSpecifies the SameSite attribute of the cookie.
The SameSite attribute restricts when cookies are sent to the server, helping to protect against certain types of cross-site request forgery (CSRF) attacks.
SameSite::Strict: The cookie is only sent when making a “same-site” request, which includes requests originating from the same site as the cookie.SameSite::Lax: The cookie is sent on “same-site” requests as well as during safe “cross-site” top-level navigations (e.g., clicking a link).SameSite::None: The cookie is sent on all requests, regardless of origin.
max_age: Option<Duration>Specifies the maximum age of the cookie.
This field represents the duration for which the cookie is considered
valid before it expires. If set to None, the cookie will be
treated as a session cookie and will expire when the browser is
closed.
secure: boolIndicates whether the cookie should only be transmitted over secure (HTTPS) connections.
If true, the cookie will only be sent to the server over secure
connections. If false, the cookie may be sent over both secure and
non-secure connections.
path: StringSpecifies the path for which the cookie is valid.
The cookie will only be sent to the server when the request path matches
or is a subpath of the path specified here.
domain: Option<String>Specifies the domain for which the cookie is valid.
If Some, the cookie is only sent to the server when the request domain
matches the specified domain. If None, the cookie is valid for the
current domain.
Implementations§
source§impl CookieConfig
impl CookieConfig
Create a Cookie from the provided Session.
Examples
use tower_sessions::{CookieConfig, Session};
let session = Session::new();
let cookie_config = CookieConfig::default();
let cookie = cookie_config.build_cookie(&session);
assert_eq!(cookie.value(), session.id().to_string());Trait Implementations§
source§impl Clone for CookieConfig
impl Clone for CookieConfig
source§fn clone(&self) -> CookieConfig
fn clone(&self) -> CookieConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more