pub struct SessionManagerLayer<Store, C = PlaintextCookie>where
Store: SessionStore,
C: CookieController,{ /* private fields */ }Expand description
A layer for providing Session as a request extension.
Implementations§
Source§impl<Store, C> SessionManagerLayer<Store, C>where
Store: SessionStore,
C: CookieController,
impl<Store, C> SessionManagerLayer<Store, C>where
Store: SessionStore,
C: CookieController,
Sourcepub fn with_name<N>(self, name: N) -> SessionManagerLayer<Store, C>
pub fn with_name<N>(self, name: N) -> SessionManagerLayer<Store, C>
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) -> SessionManagerLayer<Store, C>
pub fn with_http_only(self, http_only: bool) -> SessionManagerLayer<Store, C>
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,
) -> SessionManagerLayer<Store, C>
pub fn with_same_site( self, same_site: SameSite, ) -> SessionManagerLayer<Store, C>
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) -> SessionManagerLayer<Store, C>
pub fn with_expiry(self, expiry: Expiry) -> SessionManagerLayer<Store, C>
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) -> SessionManagerLayer<Store, C>
pub fn with_secure(self, secure: bool) -> SessionManagerLayer<Store, C>
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>(self, path: P) -> SessionManagerLayer<Store, C>
pub fn with_path<P>(self, path: P) -> SessionManagerLayer<Store, C>
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>(self, domain: D) -> SessionManagerLayer<Store, C>
pub fn with_domain<D>(self, domain: D) -> SessionManagerLayer<Store, C>
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,
) -> SessionManagerLayer<Store, C>
pub fn with_always_save( self, always_save: bool, ) -> SessionManagerLayer<Store, C>
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);Source§impl<Store> SessionManagerLayer<Store>where
Store: SessionStore,
impl<Store> SessionManagerLayer<Store>where
Store: SessionStore,
Sourcepub fn new(session_store: Store) -> SessionManagerLayer<Store>
pub fn new(session_store: Store) -> SessionManagerLayer<Store>
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, C> Clone for SessionManagerLayer<Store, C>
impl<Store, C> 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 moreSource§impl<Store, C> Debug for SessionManagerLayer<Store, C>
impl<Store, C> Debug for SessionManagerLayer<Store, C>
Source§impl<S, Store, C> Layer<S> for SessionManagerLayer<Store, C>where
Store: SessionStore,
C: CookieController,
impl<S, Store, C> Layer<S> for SessionManagerLayer<Store, C>where
Store: SessionStore,
C: CookieController,
Source§type Service = CookieManager<SessionManager<S, Store, C>>
type Service = CookieManager<SessionManager<S, Store, C>>
Auto Trait Implementations§
impl<Store, C> Freeze for SessionManagerLayer<Store, C>where
C: Freeze,
impl<Store, C> RefUnwindSafe for SessionManagerLayer<Store, C>where
C: RefUnwindSafe,
Store: RefUnwindSafe,
impl<Store, C> Send for SessionManagerLayer<Store, C>
impl<Store, C> Sync for SessionManagerLayer<Store, C>where
C: Sync,
impl<Store, C> Unpin for SessionManagerLayer<Store, C>where
C: Unpin,
impl<Store, C> UnsafeUnpin for SessionManagerLayer<Store, C>where
C: UnsafeUnpin,
impl<Store, C> UnwindSafe for SessionManagerLayer<Store, C>where
C: UnwindSafe,
Store: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more