Struct tower_sessions_core::SessionManagerLayer
source · pub struct SessionManagerLayer<Store: SessionStore> { /* private fields */ }Expand description
A layer for providing Session as a request extension.
Implementations§
source§impl<Store: SessionStore> SessionManagerLayer<Store>
impl<Store: SessionStore> SessionManagerLayer<Store>
sourcepub fn with_name(self, name: &str) -> Self
pub fn with_name(self, name: &str) -> Self
Configures the name of the cookie used for the session.
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.
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.
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.
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(self, path: String) -> Self
pub fn with_path(self, path: String) -> Self
Configures the "Path" attribute of the cookie used for the session.
Examples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service =
SessionManagerLayer::new(session_store).with_path("/some/path".to_string());sourcepub fn with_domain(self, domain: String) -> Self
pub fn with_domain(self, domain: String) -> Self
Configures the "Domain" attribute of the cookie used for the session.
Examples
use tower_sessions::{MemoryStore, SessionManagerLayer};
let session_store = MemoryStore::default();
let session_service =
SessionManagerLayer::new(session_store).with_domain("localhost".to_string());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> Clone for SessionManagerLayer<Store>
impl<Store: Clone + SessionStore> Clone for SessionManagerLayer<Store>
source§fn clone(&self) -> SessionManagerLayer<Store>
fn clone(&self) -> SessionManagerLayer<Store>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more