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 more