pub struct SessionMiddleware { /* private fields */ }
session
only.Expand description
A middleware for session management in Actix Web applications.
SessionMiddleware
takes care of a few jobs:
- Instructs the session storage backend to create/update/delete/retrieve the state attached to a session according to its status and the operations that have been performed against it;
- Set/remove a cookie, on the client side, to enable a user to be consistently associated with the same session across multiple HTTP requests.
Use SessionMiddleware::new
to initialize the session framework using the default parameters.
To create a new instance of SessionMiddleware
you need to provide:
- an instance of the session storage backend you wish to use (i.e. an implementation of SessionStore);
- a secret key, to sign or encrypt the content of client-side session cookie.
§How did we choose defaults?
You should not regret adding actix-session
to your dependencies and going to production using
the default configuration. That is why, when in doubt, we opt to use the most secure option for
each configuration parameter.
We expose knobs to change the default to suit your needs—i.e., if you know what you are doing, we will not stop you. But being a subject-matter expert should not be a requirement to deploy reasonably secure implementation of sessions.
Implementations§
Source§impl SessionMiddleware
impl SessionMiddleware
Sourcepub fn new(client: Arc<dyn MemoryDB>, key: Key) -> Self
pub fn new(client: Arc<dyn MemoryDB>, key: Key) -> Self
Use SessionMiddleware::new
to initialize the session framework using the default
parameters.
To create a new instance of SessionMiddleware
you need to provide:
- an instance of the session storage backend you wish to use (i.e. an implementation of SessionStore);
- a secret key, to sign or encrypt the content of client-side session cookie.
Sourcepub fn builder(client: Arc<dyn MemoryDB>, key: Key) -> SessionMiddlewareBuilder
pub fn builder(client: Arc<dyn MemoryDB>, key: Key) -> SessionMiddlewareBuilder
A fluent API to configure SessionMiddleware
.
It takes as input the two required inputs to create a new instance of SessionMiddleware
:
- an instance of the session storage backend you wish to use (i.e. an implementation of SessionStore);
- a secret key, to sign or encrypt the content of client-side session cookie.
Trait Implementations§
Source§impl Clone for SessionMiddleware
impl Clone for SessionMiddleware
Source§fn clone(&self) -> SessionMiddleware
fn clone(&self) -> SessionMiddleware
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<S, B> Transform<S, ServiceRequest> for SessionMiddlewarewhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: MessageBody + 'static,
impl<S, B> Transform<S, ServiceRequest> for SessionMiddlewarewhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: MessageBody + 'static,
Source§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Source§type Future = Ready<Result<<SessionMiddleware as Transform<S, ServiceRequest>>::Transform, <SessionMiddleware as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<SessionMiddleware as Transform<S, ServiceRequest>>::Transform, <SessionMiddleware as Transform<S, ServiceRequest>>::InitError>>
Source§fn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Auto Trait Implementations§
impl Freeze for SessionMiddleware
impl !RefUnwindSafe for SessionMiddleware
impl !Send for SessionMiddleware
impl !Sync for SessionMiddleware
impl Unpin for SessionMiddleware
impl !UnwindSafe for SessionMiddleware
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