Struct tower_sessions::service::SessionManagerLayer
source ยท 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_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