Struct SessionLayer

Source
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>

Source

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>

Source

pub fn signed(self) -> SessionLayer<T, Store, SignedCookie>

Authenticate cookies.

TODO: More documentation

Source

pub fn private(self) -> SessionLayer<T, Store, PrivateCookie>

Encrypt cookies.

TODO: More documentation

Source

pub fn cookie_name(self, name: impl Into<Cow<'static, str>>) -> Self

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"

Source

pub fn domain(self, domain: impl Into<Cow<'static, str>>) -> Self

Set the Domain attribute in the Set-Cookie response header.

Source

pub fn http_only(self, enable: bool) -> Self

Set whether to add the HttpOnly attribute in the Set-Cookie response header.

Source

pub fn path(self, path: impl Into<Cow<'static, str>>) -> Self

Set the Path attribute in the Set-Cookie response header.

Source

pub fn same_site(self, same_site: SameSite) -> Self

Set the SameSite attribute in the Set-Cookie response header.

Source

pub fn secure(self, enable: bool) -> Self

Set whether to add the Secure attribute in the Set-Cookie response header.

Source

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>

Source

pub fn plain(store: Arc<Store>) -> SessionLayer<T, Store, PlainCookie>

Create a new SessionLayer that doesn’t sign or encrypt cookies.

Trait Implementations§

Source§

impl<T, Store: SessionStore<T>, C: CookieSecurity> Clone for SessionLayer<T, Store, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, Store: Debug + SessionStore<T>, C: Debug + CookieSecurity> Debug for SessionLayer<T, Store, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, T, Store: SessionStore<T>, C: CookieSecurity> Layer<S> for SessionLayer<T, Store, C>

Source§

type Service = SessionManager<S, T, Store, C>

The wrapped service
Source§

fn layer(&self, inner: S) -> Self::Service

Wrap the given service with the middleware, returning a new service that has been decorated with the middleware.

Auto Trait Implementations§

§

impl<T, Store, C> Freeze for SessionLayer<T, Store, C>
where C: Freeze,

§

impl<T, Store, C> RefUnwindSafe for SessionLayer<T, Store, C>
where C: RefUnwindSafe, Store: RefUnwindSafe,

§

impl<T, Store, C> Send for SessionLayer<T, Store, C>
where C: Send,

§

impl<T, Store, C> Sync for SessionLayer<T, Store, C>
where C: Sync,

§

impl<T, Store, C> Unpin for SessionLayer<T, Store, C>
where C: Unpin,

§

impl<T, Store, C> UnwindSafe for SessionLayer<T, Store, C>
where C: UnwindSafe, Store: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,