pub struct SessionManagerLayer<Store: SessionStore, C: CookieController = PlaintextCookie> { /* private fields */ }Expand description
A layer for providing Session as a request extension.
Implementationsยง
Sourceยงimpl<Store: SessionStore, C: CookieController> SessionManagerLayer<Store, C>
impl<Store: SessionStore, C: CookieController> SessionManagerLayer<Store, C>
Sourcepub fn with_name<N: Into<Cow<'static, str>>>(self, name: N) -> Self
pub fn with_name<N: Into<Cow<'static, str>>>(self, name: N) -> Self
Configures the name of the cookie used for the session.
The default value is "id".
ยงExamples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_name("my.sid");Sourcepub fn with_http_only(self, http_only: bool) -> Self
pub fn with_http_only(self, http_only: bool) -> Self
Configures the "HttpOnly" attribute of the cookie used for the
session.
ยงโ ๏ธ Warning: Cross-site scripting risk
Applications should generally not override the default value of
true. If you do, you are exposing your application to increased risk
of cookie theft via techniques like cross-site scripting.
ยงExamples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_http_only(true);Sourcepub fn with_same_site(self, same_site: SameSite) -> Self
pub fn with_same_site(self, same_site: SameSite) -> Self
Configures the "SameSite" attribute of the cookie used for the
session.
The default value is SameSite::Strict.
ยงExamples
use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_same_site(SameSite::Lax);Sourcepub fn with_expiry(self, expiry: Expiry) -> Self
pub fn with_expiry(self, expiry: Expiry) -> Self
Configures the "Max-Age" attribute of the cookie used for the session.
The default value is None.
ยงExamples
use time::Duration;
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_expiry = Expiry::OnInactivity(Duration::hours(1));
let session_service = SessionManagerLayer::new(session_store).with_expiry(session_expiry);Sourcepub fn with_secure(self, secure: bool) -> Self
pub fn with_secure(self, secure: bool) -> Self
Configures the "Secure" attribute of the cookie used for the session.
The default value is true.
ยงExamples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_secure(true);Sourcepub fn with_path<P: Into<Cow<'static, str>>>(self, path: P) -> Self
pub fn with_path<P: Into<Cow<'static, str>>>(self, path: P) -> Self
Configures the "Path" attribute of the cookie used for the session.
The default value is "/".
ยงExamples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_path("/some/path");Sourcepub fn with_domain<D: Into<Cow<'static, str>>>(self, domain: D) -> Self
pub fn with_domain<D: Into<Cow<'static, str>>>(self, domain: D) -> Self
Configures the "Domain" attribute of the cookie used for the session.
The default value is None.
ยงExamples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_domain("localhost");Sourcepub fn with_always_save(self, always_save: bool) -> Self
pub fn with_always_save(self, always_save: bool) -> Self
Configures whether unmodified session should be saved on read or not.
When the value is true, the session will be saved even if it was not
changed.
This is useful when you want to reset Session expiration time
on any valid request at the cost of higher SessionStore write
activity and transmitting set-cookie header with each response.
It makes sense to use this setting with relative session expiration
values, such as Expiry::OnInactivity(Duration). This setting will
not cause session id to be cycled on save.
The default value is false.
ยงExamples
use time::Duration;
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_expiry = Expiry::OnInactivity(Duration::hours(1));
let session_service = SessionManagerLayer::new(session_store)
.with_expiry(session_expiry)
.with_always_save(true);Sourcepub fn with_signed(self, key: Key) -> SessionManagerLayer<Store, SignedCookie>
pub fn with_signed(self, key: Key) -> SessionManagerLayer<Store, SignedCookie>
Manages the session cookie via a signed interface.
See SignedCookies.
use tower_sessions::{cookie::Key, MemoryStore, SessionManagerLayer};
let key = { /* a cryptographically random key >= 64 bytes */ };
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_signed(key);Sourcepub fn with_private(self, key: Key) -> SessionManagerLayer<Store, PrivateCookie>
pub fn with_private(self, key: Key) -> SessionManagerLayer<Store, PrivateCookie>
Manages the session cookie via an encrypted interface.
See PrivateCookies.
use tower_sessions::{cookie::Key, MemoryStore, SessionManagerLayer};
let key = { /* a cryptographically random key >= 64 bytes */ };
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store).with_private(key);Sourceยงimpl<Store: SessionStore> SessionManagerLayer<Store>
impl<Store: SessionStore> SessionManagerLayer<Store>
Sourcepub fn new(session_store: Store) -> Self
pub fn new(session_store: Store) -> Self
Create a new SessionManagerLayer with the provided session store
and default cookie configuration.
ยงExamples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service = SessionManagerLayer::new(session_store);Trait Implementationsยง
Sourceยงimpl<Store: Clone + SessionStore, C: Clone + CookieController> Clone for SessionManagerLayer<Store, C>
impl<Store: Clone + SessionStore, C: Clone + CookieController> Clone for SessionManagerLayer<Store, C>
Sourceยงfn clone(&self) -> SessionManagerLayer<Store, C>
fn clone(&self) -> SessionManagerLayer<Store, C>
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more