Struct axum_sessions::SessionLayer
source · [−]pub struct SessionLayer<Store> { /* private fields */ }
Implementations
sourceimpl<Store: SessionStore> SessionLayer<Store>
impl<Store: SessionStore> SessionLayer<Store>
sourcepub fn new(store: Store, secret: &[u8]) -> Self
pub fn new(store: Store, secret: &[u8]) -> Self
Creates a layer which will attach a SessionHandle
to requests via an
extension. This session is derived from a cryptographically signed
cookie. When the client sends a valid, known cookie then the session is
hydrated from this. Otherwise a new cookie is created and returned in
the response.
Panics
SessionLayer::new
will panic if the secret is less than 64 bytes.
Customization
The configuration of the session may be adjusted according to the needs of your application:
SessionLayer::new(
MemoryStore::new(),
b"please do not hardcode your secret; instead use a
cryptographically secure value",
)
.with_cookie_name("your.cookie.name")
.with_cookie_path("/some/path")
.with_cookie_domain("www.example.com")
.with_same_site_policy(SameSite::Lax)
.with_session_ttl(Some(Duration::from_secs(60 * 5)))
.with_save_unchanged(false)
.with_secure(true);
sourcepub fn with_save_unchanged(self, save_unchanged: bool) -> Self
pub fn with_save_unchanged(self, save_unchanged: bool) -> Self
When true
, a session cookie will always be set. When false
the
session data must be modified in order for it to be set. Defaults to
true
.
Sets a cookie for the session. Defaults to "/"
.
Sets a cookie name for the session. Defaults to "axum.sid"
.
Sets a cookie domain for the session. Defaults to None
.
sourcepub fn with_same_site_policy(self, policy: SameSite) -> Self
pub fn with_same_site_policy(self, policy: SameSite) -> Self
Sets a cookie same site policy for the session. Defaults to
SameSite::Strict
.
sourcepub fn with_session_ttl(self, session_ttl: Option<Duration>) -> Self
pub fn with_session_ttl(self, session_ttl: Option<Duration>) -> Self
Sets a cookie time-to-live (ttl) for the session. Defaults to
Duration::from_secs(60 * 60 24)
; one day.
sourcepub fn with_secure(self, secure: bool) -> Self
pub fn with_secure(self, secure: bool) -> Self
Sets a cookie secure attribute for the session. Defaults to true
.
Trait Implementations
sourceimpl<Store: Clone> Clone for SessionLayer<Store>
impl<Store: Clone> Clone for SessionLayer<Store>
sourcefn clone(&self) -> SessionLayer<Store>
fn clone(&self) -> SessionLayer<Store>
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<S, Store: SessionStore> Layer<S> for SessionLayer<Store>
impl<S, Store: SessionStore> Layer<S> for SessionLayer<Store>
Auto Trait Implementations
impl<Store> RefUnwindSafe for SessionLayer<Store> where
Store: RefUnwindSafe,
impl<Store> Send for SessionLayer<Store> where
Store: Send,
impl<Store> Sync for SessionLayer<Store> where
Store: Sync,
impl<Store> Unpin for SessionLayer<Store> where
Store: Unpin,
impl<Store> UnwindSafe for SessionLayer<Store> where
Store: UnwindSafe,
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