Struct axum_session::SessionConfig
source Ā· pub struct SessionConfig {Show 25 fields
pub(crate) store_name: Cow<'static, str>,
pub(crate) session_name: Cow<'static, str>,
pub(crate) key_name: Cow<'static, str>,
pub(crate) cookie_domain: Option<Cow<'static, str>>,
pub(crate) cookie_http_only: bool,
pub(crate) cookie_max_age: Option<Duration>,
pub(crate) cookie_path: Cow<'static, str>,
pub(crate) cookie_same_site: SameSite,
pub(crate) cookie_secure: bool,
pub(crate) session_mode: SessionMode,
pub(crate) lifespan: Duration,
pub(crate) max_lifespan: Duration,
pub(crate) purge_update: Duration,
pub(crate) purge_database_update: Duration,
pub(crate) always_save: bool,
pub(crate) memory_lifespan: Duration,
pub(crate) table_name: Cow<'static, str>,
pub(crate) key: Option<Key>,
pub(crate) database_key: Option<Key>,
pub(crate) security_mode: SecurityMode,
pub(crate) filter_expected_elements: u64,
pub(crate) filter_false_positive_probability: f64,
pub(crate) use_bloom_filters: bool,
pub(crate) clear_check_on_load: bool,
pub(crate) prefix_with_host: bool,
}Expand description
Configuration for how the Session and Cookies are used.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default();Fields§
§store_name: Cow<'static, str>The Cookie or Header name that contains a boolean for session saving. only used when session_mode is set to SessionMode::OptIn or Manual.
session_name: Cow<'static, str>Session Cookie or Header name.
key_name: Cow<'static, str>Session key Cookie or Header name.
Session cookie domain.
Session cookie http only flag.
Session cookie max age None means the browser deletes cookie on close. Please make sure the Duration is longer than max_lifespan.
Session cookie path.
Resticts how Cookies are sent cross-site. Default is SameSite::Lax.
Session cookie secure flag.
session_mode: SessionModeDisables the need to avoid session saving.
lifespan: DurationSessions the minimal lifespan a session can live in the database before expiring.
max_lifespan: DurationSessions the maximum lifespan a session can live in the database before expiring. This is generally used when a Session is set to be Long Term.
purge_update: DurationThis value represents the duration for how often sessionās data gets purged from memory per request.
purge_database_update: DurationThis value represents the duration for how often sessionās data gets purged from the database per request.
always_save: boolIgnoreās the update checks and will always save the session to the database if set to true.
memory_lifespan: DurationSession Memory lifespan, deturmines when to unload it from memory this works fine since the data can stay in the database till its needed if not yet expired.
table_name: Cow<'static, str>Session Database table name default is async_sessions
key: Option<Key>Encyption Key used to encypt cookies for confidentiality, integrity, and authenticity.
database_key: Option<Key>Encyption Key used to encypt keys stored in the database for confidentiality.
security_mode: SecurityModeSet how Secure you want SessionIDās to be stored as.
filter_expected_elements: u64How many Elements could we see at one time in the Table? So if you have 1000 unique visitors a second and each generate a UUID. That would be 1000 * 60(secs) * 60(mins) * 24(hours) to get 1 days worth of visitors.
filter_false_positive_probability: f64The probability of how many allowable false positives you want to have based on the expected elements. 0.01 is a good starting point.
use_bloom_filters: boolThis enabled using a counting bloom filter. If this is taking to much Memory or is to slow or you just dont want the false positives it can give you can disable it by setting it to false. This will reduce memory usage. By default this is enabled unless the specific database cant function with it then disabled.
clear_check_on_load: boolThis is to be used when your handling multiple Parallel Sessions to prevent the next one from unloaded data.
prefix_with_host: boolThis is used to append __Host- to the front of all Cookie names to prevent sub domain usage. This will not append to Headers only Cookies. It is enabled by default.
Implementations§
source§impl SessionConfig
impl SessionConfig
sourcepub fn new() -> Self
pub fn new() -> Self
Creates Default configuration of SessionConfig.
This is equivalent to the SessionConfig::default().
sourcepub fn with_store_name(self, name: impl Into<Cow<'static, str>>) -> Self
pub fn with_store_name(self, name: impl Into<Cow<'static, str>>) -> Self
Set the sessionās store Cookie or Header name.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_store_name("my_stored_cookie".to_owned());Setās the sessionās cookieās domain name.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_cookie_domain("www.helpme.com".to_string());sourcepub fn with_session_name(self, name: impl Into<Cow<'static, str>>) -> Self
pub fn with_session_name(self, name: impl Into<Cow<'static, str>>) -> Self
Setās the sessionās Cookie or Header name.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_session_name("my_cookie");sourcepub fn with_key_name(self, name: impl Into<Cow<'static, str>>) -> Self
pub fn with_key_name(self, name: impl Into<Cow<'static, str>>) -> Self
Setās the sessionās key Cookie or Header name.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_key_name("my_key_cookie");Setās the sessionās cookieās path.
This is used to deturmine when the cookie takes effect within the website path. Leave as default (ā/ā) for cookie to be used site wide.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_cookie_path("/");Setās the sessionās cookieās Same Site Setting for Cross-Site restrictions.
Examples
use axum_session::SessionConfig;
use cookie::SameSite;
let config = SessionConfig::default().with_cookie_same_site(SameSite::Strict);sourcepub fn with_mode(self, mode: SessionMode) -> Self
pub fn with_mode(self, mode: SessionMode) -> Self
Setās whether the session Persistantly stores data or on stores if storable.
Examples
use axum_session::{SessionMode, SessionConfig};
use cookie::SameSite;
let config = SessionConfig::default().with_mode(SessionMode::Persistent);sourcepub fn with_http_only(self, is_set: bool) -> Self
pub fn with_http_only(self, is_set: bool) -> Self
Setās the sessionās cookieās to http only.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_http_only(false);sourcepub fn with_lifetime(self, time: Duration) -> Self
pub fn with_lifetime(self, time: Duration) -> Self
Setās the sessionās lifetime (expiration time) within database storage. This should be equal too or less than the Cookies Expiration time.
Examples
use axum_session::SessionConfig;
use chrono::Duration;
let config = SessionConfig::default().with_lifetime(Duration::days(32));sourcepub fn with_max_age(self, time: Option<Duration>) -> Self
pub fn with_max_age(self, time: Option<Duration>) -> Self
Setās the sessionās cookies max_age (expiration time).
If this is set to None then the Cookie will be unloaded on browser Close. Set this to be the duration of max_lifespan or longer to prevent session drops. This is generally in a duration of how many Days a cookie should live in the browser. Please Ensure the Duration is greater or equal to max_lifespan for proper storage.
Examples
use axum_session::SessionConfig;
use chrono::Duration;
let config = SessionConfig::default().with_max_age(Some(Duration::days(64)));sourcepub fn with_max_lifetime(self, time: Duration) -> Self
pub fn with_max_lifetime(self, time: Duration) -> Self
Setās the sessionās long term lifetime (expiration time) within database storage.
Examples
use axum_session::SessionConfig;
use chrono::Duration;
let config = SessionConfig::default().with_max_lifetime(Duration::days(32));sourcepub fn with_memory_lifetime(self, time: Duration) -> Self
pub fn with_memory_lifetime(self, time: Duration) -> Self
Setās the sessionās lifetime (expiration time) within memory storage. This setting should be Less than lifespan and max_lifespan. This is to Unload the data from memory and allow it to stay stored in the database.
Set this to Duration::zero() if you dont want it to stay in memory. Warning: This will cause it to be loaded from the database each request.
Examples
use axum_session::SessionConfig;
use chrono::Duration;
let config = SessionConfig::default().with_memory_lifetime(Duration::days(32));sourcepub fn with_purge_update(self, duration: Duration) -> Self
pub fn with_purge_update(self, duration: Duration) -> Self
This value represents the offset duration for how often session purge for memory is ran.
Examples
use axum_session::SessionConfig;
use chrono::Duration;
let config = SessionConfig::default().with_purge_update(Duration::hours(1));sourcepub fn with_purge_database_update(self, duration: Duration) -> Self
pub fn with_purge_database_update(self, duration: Duration) -> Self
This value represents the offset duration for how often session purge for database is ran. If using Redis or any auto purge database this Setting will be ignored.
Examples
use axum_session::SessionConfig;
use chrono::Duration;
let config = SessionConfig::default().with_purge_database_update(Duration::hours(5));sourcepub fn with_always_save(self, always_save: bool) -> Self
pub fn with_always_save(self, always_save: bool) -> Self
This value represents if the database should check for updates to save or to just save the data regardless of updates. When set to true it will disable the update checks.
Examples
use axum_session::SessionConfig;
use chrono::Duration;
let config = SessionConfig::default().with_always_save(true);sourcepub fn with_secure(self, is_set: bool) -> Self
pub fn with_secure(self, is_set: bool) -> Self
Setās the sessionās secure flag for if it gets sent over https.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_secure(true);sourcepub fn with_table_name(self, table_name: impl Into<Cow<'static, str>>) -> Self
pub fn with_table_name(self, table_name: impl Into<Cow<'static, str>>) -> Self
Setās the sessionās database table name.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_table_name("my_table");sourcepub fn with_key(self, key: Key) -> Self
pub fn with_key(self, key: Key) -> Self
Setās the sessionās cookie encyption key enabling private cookies.
When Set it will enforce Private cookies across all Sessions. If you use Key::generate() it will make a new key each server reboot. To prevent this make and save a key to a config file for long term usage. For Extra Security Regenerate the key every so many months to a year. A new key will invalidate all old Sessions so it be wise to run session_store.clear_store() on reboot.
Must be Set to Some() in order to use Security::PerSession.
Examples
use axum_session::{Key, SessionConfig};
let config = SessionConfig::default().with_key(Key::generate());sourcepub fn with_database_key(self, key: Key) -> Self
pub fn with_database_key(self, key: Key) -> Self
Setās the sessionās database encyption key for per session key storage.
Must be Set to Some() in order to use Security::PerSession or will panic if not.
Examples
use axum_session::{Key, SessionConfig};
let config = SessionConfig::default().with_key(Key::generate());sourcepub fn with_security_mode(self, mode: SecurityMode) -> Self
pub fn with_security_mode(self, mode: SecurityMode) -> Self
Setās the sessionās security mode.
Examples
use axum_session::{SecurityMode, SessionConfig};
let config = SessionConfig::default().with_security_mode(SecurityMode::PerSession);sourcepub fn with_filter_expected_elements(self, elements: u64) -> Self
pub fn with_filter_expected_elements(self, elements: u64) -> Self
Setās the sessionās filters expected elements. Please Set this by a daily value. Example: 1000 * 60(secs) * 60(mins) * 24(hours) to get 1 days worth of visitors.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_filter_expected_elements(100_000);sourcepub fn with_filter_false_positive_probability(self, probability: f64) -> Self
pub fn with_filter_false_positive_probability(self, probability: f64) -> Self
Setās the sessionās filters False Posistive probability when creating and comparing UUID.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_filter_false_positive_probability(0.01);sourcepub fn with_bloom_filter(self, enable: bool) -> Self
pub fn with_bloom_filter(self, enable: bool) -> Self
Setās the sessionās bloom filters to be disabled or enabled. By default they are enabled.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_bloom_filter(true);sourcepub fn get_session_name(&self) -> String
pub fn get_session_name(&self) -> String
Getās the sessionās Cookie/Header name
Examples
use axum_session::SessionConfig;
let name = SessionConfig::default().get_session_name();sourcepub fn get_key_name(&self) -> String
pub fn get_key_name(&self) -> String
Getās the sessionās Key Cookie/Header name
Examples
use axum_session::SessionConfig;
let name = SessionConfig::default().get_key_name();sourcepub fn get_store_name(&self) -> String
pub fn get_store_name(&self) -> String
Getās the sessionās store booleans Cookie/Header name
Examples
use axum_session::SessionConfig;
let name = SessionConfig::default().get_store_name();sourcepub fn with_clear_check_on_load(self, enable: bool) -> Self
pub fn with_clear_check_on_load(self, enable: bool) -> Self
Setās the sessionās loading to either true: unload data if checks fail or false: bypass.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_bloom_filter(true);sourcepub fn with_prefix_with_host(self, enable: bool) -> Self
pub fn with_prefix_with_host(self, enable: bool) -> Self
Setās the sessionās prefix_with_host to either true: __Host- gets prefixed to the cookie names false: __Host- does not get prepended.
__Host- prefix: Cookies with names starting with __Host- must be set with the secure flag, must be from a secure page (HTTPS), must not have a domain specified (and therefore, are not sent to subdomains), and the path must be /.
Examples
use axum_session::SessionConfig;
let config = SessionConfig::default().with_prefix_with_host(true);Trait Implementations§
source§impl Clone for SessionConfig
impl Clone for SessionConfig
source§fn clone(&self) -> SessionConfig
fn clone(&self) -> SessionConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for SessionConfig
impl Debug for SessionConfig
Auto Trait Implementations§
impl RefUnwindSafe for SessionConfig
impl Send for SessionConfig
impl Sync for SessionConfig
impl Unpin 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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,
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>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_mut() into the pipe
function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.