Struct actix_session::config::BrowserSession
source · [−]pub struct BrowserSession { /* private fields */ }
Expand description
A session lifecycle strategy where the session cookie expires when the browser’s current session ends.
When does a browser session end? It depends on the browser. Chrome, for example, will often continue running in the background when the browser is closed—session cookies are not deleted and they will still be available when the browser is opened again. Check the documentation of the browsers you are targeting for up-to-date information.
Implementations
sourceimpl BrowserSession
impl BrowserSession
sourcepub fn state_ttl(self, ttl: Duration) -> Self
pub fn state_ttl(self, ttl: Duration) -> Self
Sets a time-to-live (TTL) when storing the session state in the storage backend.
We do not want to store session states indefinitely, otherwise we will inevitably run out of storage by holding on to the state of countless abandoned or expired sessions!
We are dealing with the lifecycle of two uncorrelated object here: the session cookie and the session state. It is not a big issue if the session state outlives the cookie— we are wasting some space in the backend storage, but it will be cleaned up eventually. What happens, instead, if the cookie outlives the session state? A new session starts— e.g. if sessions are being used for authentication, the user is de-facto logged out.
It is not possible to predict with certainty how long a browser session is going to
last—you need to provide a reasonable upper bound. You do so via state_ttl
—it dictates
what TTL should be used for session state when the lifecycle of the session cookie is
tied to the browser session length. SessionMiddleware
will default to 1 day if
state_ttl
is left unspecified.
You can mitigate the risk of the session cookie outliving the session state by
specifying a more aggressive state TTL extension policy - check out
BrowserSession::state_ttl_extension_policy
for more details.
sourcepub fn state_ttl_extension_policy(
self,
ttl_extension_policy: TtlExtensionPolicy
) -> Self
pub fn state_ttl_extension_policy(
self,
ttl_extension_policy: TtlExtensionPolicy
) -> Self
Determine under what circumstances the TTL of your session state should be extended.
Defaults to TtlExtensionPolicy::OnStateChanges
if left unspecified.
See TtlExtensionPolicy
for more details.
Trait Implementations
sourceimpl Clone for BrowserSession
impl Clone for BrowserSession
sourcefn clone(&self) -> BrowserSession
fn clone(&self) -> BrowserSession
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for BrowserSession
impl Debug for BrowserSession
sourceimpl Default for BrowserSession
impl Default for BrowserSession
sourceimpl From<BrowserSession> for SessionLifecycle
impl From<BrowserSession> for SessionLifecycle
sourcefn from(session: BrowserSession) -> Self
fn from(session: BrowserSession) -> Self
Converts to this type from the input type.
Auto Trait Implementations
impl RefUnwindSafe for BrowserSession
impl Send for BrowserSession
impl Sync for BrowserSession
impl Unpin for BrowserSession
impl UnwindSafe for BrowserSession
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more