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.

§cookie_domain: Option<Cow<'static, str>>

Session cookie domain.

§cookie_http_only: bool

Session cookie http only flag.

§cookie_max_age: Option<Duration>

Session cookie max age None means the browser deletes cookie on close. Please make sure the Duration is longer than max_lifespan.

§cookie_path: Cow<'static, str>

Session cookie path.

§cookie_same_site: SameSite

Resticts how Cookies are sent cross-site. Default is SameSite::Lax.

§cookie_secure: bool

Session cookie secure flag.

§session_mode: SessionMode

Disables the need to avoid session saving.

§lifespan: Duration

Sessions the minimal lifespan a session can live in the database before expiring.

§max_lifespan: Duration

Sessions 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: Duration

This value represents the duration for how often session’s data gets purged from memory per request.

§purge_database_update: Duration

This value represents the duration for how often session’s data gets purged from the database per request.

§always_save: bool

Ignore’s the update checks and will always save the session to the database if set to true.

§memory_lifespan: Duration

Session 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: SecurityMode

Set how Secure you want SessionID’s to be stored as.

§filter_expected_elements: u64

How 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: f64

The 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: bool

This 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: bool

This is to be used when your handling multiple Parallel Sessions to prevent the next one from unloaded data.

§prefix_with_host: bool

This 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

source

pub fn new() -> Self

Creates Default configuration of SessionConfig. This is equivalent to the SessionConfig::default().

source

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());
source

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");
source

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);
source

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);
source

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);
source

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));
source

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)));
source

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));
source

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));
source

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));
source

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));
source

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);
source

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);
source

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");
source

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());
source

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());
source

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);
source

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);
source

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);
source

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);
source

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();
source

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();
source

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();
source

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);
source

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

source§

fn clone(&self) -> SessionConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SessionConfig

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for SessionConfig

source§

fn default() -> Self

Returns the ā€œdefault valueā€ for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> Twhere Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for Twhere T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pipe for Twhere T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,

Borrows 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,

Mutably borrows 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,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

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,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> Rwhere Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Immutable access to the 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,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Immutable access to the 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,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .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,

Calls .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,

Calls .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,

Calls .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,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool

§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool