#[non_exhaustive]pub struct SessionConfig {
pub cookie_name: String,
pub ttl: Duration,
pub secure: bool,
pub http_only: bool,
pub same_site: Option<String>,
pub domain: Option<String>,
pub path: String,
}Expand description
Session configuration
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.Cookie name
ttl: DurationSession TTL
secure: boolHTTPS-only cookie
http_only: boolHttpOnly flag
same_site: Option<String>SameSite attribute
domain: Option<String>Domain
path: StringPath
Implementations§
Source§impl SessionConfig
impl SessionConfig
Sourcepub fn new(cookie_name: String, ttl: Duration) -> Self
pub fn new(cookie_name: String, ttl: Duration) -> Self
Create a new configuration
§Examples
use std::time::Duration;
use reinhardt_middleware::session::SessionConfig;
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600));
assert_eq!(config.cookie_name, "sessionid");
assert_eq!(config.ttl, Duration::from_secs(3600));Sourcepub fn with_secure(self) -> Self
pub fn with_secure(self) -> Self
Enable secure cookie
§Examples
use std::time::Duration;
use reinhardt_middleware::session::SessionConfig;
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600))
.with_secure();
assert!(config.secure);Sourcepub fn with_http_only(self, http_only: bool) -> Self
pub fn with_http_only(self, http_only: bool) -> Self
Set HttpOnly flag
§Examples
use std::time::Duration;
use reinhardt_middleware::session::SessionConfig;
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600))
.with_http_only(false);
assert!(!config.http_only);Sourcepub fn with_same_site(self, same_site: String) -> Self
pub fn with_same_site(self, same_site: String) -> Self
Set SameSite attribute
§Examples
use std::time::Duration;
use reinhardt_middleware::session::SessionConfig;
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600))
.with_same_site("Strict".to_string());Sourcepub fn with_domain(self, domain: String) -> Self
pub fn with_domain(self, domain: String) -> Self
Set domain
§Examples
use std::time::Duration;
use reinhardt_middleware::session::SessionConfig;
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600))
.with_domain("example.com".to_string());Sourcepub fn with_path(self, path: String) -> Self
pub fn with_path(self, path: String) -> Self
Set path
§Examples
use std::time::Duration;
use reinhardt_middleware::session::SessionConfig;
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600))
.with_path("/app".to_string());
assert_eq!(config.path, "/app");Sourcepub fn from_settings(settings: &Settings) -> Self
pub fn from_settings(settings: &Settings) -> Self
Create a SessionConfig from application Settings
Maps Settings.core.security.session_cookie_secure to SessionConfig.secure.
§Examples
use reinhardt_conf::Settings;
use reinhardt_middleware::session::SessionConfig;
#[allow(deprecated)]
let settings = Settings::default();
#[allow(deprecated)]
let config = SessionConfig::from_settings(&settings);
assert!(!config.secure);Trait Implementations§
Source§impl Clone for SessionConfig
impl Clone for SessionConfig
Source§fn clone(&self) -> SessionConfig
fn clone(&self) -> SessionConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SessionConfig
impl Debug for SessionConfig
Auto Trait Implementations§
impl Freeze for SessionConfig
impl RefUnwindSafe for SessionConfig
impl Send for SessionConfig
impl Sync for SessionConfig
impl Unpin for SessionConfig
impl UnsafeUnpin for SessionConfig
impl UnwindSafe for SessionConfig
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().