pub struct SessionLayer<T, Store: SessionStore<T>, C: CookieSecurity = PrivateCookie> { /* private fields */ }Expand description
A layer that provides Session as a request extension.
§Example
TODO: Provide an example
§Test
TODO: Replace with example
use std::sync::Arc;
use tower_sesh::{store::MemoryStore, SessionLayer};
#[derive(Clone)]
struct SessionData {
foo: String,
bar: u64,
}
let key = &[0; 64];
let store = Arc::new(MemoryStore::<SessionData>::new());
let session_layer = SessionLayer::new(store, key);Implementations§
Source§impl<T, Store: SessionStore<T>> SessionLayer<T, Store>
impl<T, Store: SessionStore<T>> SessionLayer<T, Store>
Sourcepub fn new(store: Arc<Store>, key: &[u8]) -> SessionLayer<T, Store>
pub fn new(store: Arc<Store>, key: &[u8]) -> SessionLayer<T, Store>
Create a new SessionLayer.
TODO: More documentation
Source§impl<T, Store: SessionStore<T>, C: CookieSecurity> SessionLayer<T, Store, C>
impl<T, Store: SessionStore<T>, C: CookieSecurity> SessionLayer<T, Store, C>
Sourcepub fn signed(self) -> SessionLayer<T, Store, SignedCookie>
pub fn signed(self) -> SessionLayer<T, Store, SignedCookie>
Authenticate cookies.
TODO: More documentation
Sourcepub fn private(self) -> SessionLayer<T, Store, PrivateCookie>
pub fn private(self) -> SessionLayer<T, Store, PrivateCookie>
Encrypt cookies.
TODO: More documentation
Set the name of the cookie used to store a session id.
It is recommended by OWASP that the name should not be extremely descriptive nor offer unneccessary details about the purpose and meaning of the cookie.
Default: "id"
Sourcepub fn domain(self, domain: impl Into<Cow<'static, str>>) -> Self
pub fn domain(self, domain: impl Into<Cow<'static, str>>) -> Self
Set the Domain attribute in the Set-Cookie response header.
Sourcepub fn http_only(self, enable: bool) -> Self
pub fn http_only(self, enable: bool) -> Self
Set whether to add the HttpOnly attribute in the Set-Cookie
response header.
Sourcepub fn path(self, path: impl Into<Cow<'static, str>>) -> Self
pub fn path(self, path: impl Into<Cow<'static, str>>) -> Self
Set the Path attribute in the Set-Cookie response header.
Sourcepub fn same_site(self, same_site: SameSite) -> Self
pub fn same_site(self, same_site: SameSite) -> Self
Set the SameSite attribute in the Set-Cookie response header.
Sourcepub fn secure(self, enable: bool) -> Self
pub fn secure(self, enable: bool) -> Self
Set whether to add the Secure attribute in the Set-Cookie
response header.
Sourcepub fn ignore_invalid_session(self, enable: bool) -> Self
pub fn ignore_invalid_session(self, enable: bool) -> Self
Changes behavior of the Session extractor when an error occurs
while deserializing session data.
If false, a deserialization error will cause the extractor to fail.
If true, a deserialization error will be treated as if there is no
existing session. In that case, an empty Session object is provided,
and writing to it will overwrite the existing session.
Default is true.
TODO: Link to Session migration, which should talk about strategies for avoiding session invalidation.
Source§impl<T, Store: SessionStore<T>> SessionLayer<T, Store, PlainCookie>
impl<T, Store: SessionStore<T>> SessionLayer<T, Store, PlainCookie>
Sourcepub fn plain(store: Arc<Store>) -> SessionLayer<T, Store, PlainCookie>
pub fn plain(store: Arc<Store>) -> SessionLayer<T, Store, PlainCookie>
Create a new SessionLayer that doesn’t sign or encrypt cookies.