Struct actix_session::CookieSession
source · [−]pub struct CookieSession(_);
Expand description
Use cookies for session storage.
CookieSession
creates sessions which are limited to storing
fewer than 4000 bytes of data (as the payload must fit into a single
cookie). An Internal Server Error is generated if the session contains more
than 4000 bytes.
A cookie may have a security policy of signed or private. Each has a
respective CookieSession
constructor.
A signed cookie is stored on the client as plaintext alongside a signature such that the cookie may be viewed but not modified by the client.
A private cookie is stored on the client as encrypted text such that it may neither be viewed nor modified by the client.
The constructors take a key as an argument. This is the private key for cookie session - when this value is changed, all session data is lost. The constructors will panic if the key is less than 32 bytes in length.
The backend relies on cookie
crate to create and read cookies.
By default all cookies are percent encoded, but certain symbols may
cause troubles when reading cookie, if they are not properly percent encoded.
Examples
use actix_session::CookieSession;
use actix_web::{web, App, HttpResponse, HttpServer};
let app = App::new().wrap(
CookieSession::signed(&[0; 32])
.domain("www.rust-lang.org")
.name("actix_session")
.path("/")
.secure(true))
.service(web::resource("/").to(|| HttpResponse::Ok()));
Implementations
sourceimpl CookieSession
impl CookieSession
sourcepub fn signed(key: &[u8]) -> CookieSession
pub fn signed(key: &[u8]) -> CookieSession
Construct new signed CookieSession
instance.
Panics if key length is less than 32 bytes.
sourcepub fn private(key: &[u8]) -> CookieSession
pub fn private(key: &[u8]) -> CookieSession
Construct new private CookieSession
instance.
Panics if key length is less than 32 bytes.
sourcepub fn path<S: Into<String>>(self, value: S) -> CookieSession
pub fn path<S: Into<String>>(self, value: S) -> CookieSession
Sets the path
field in the session cookie being built.
sourcepub fn name<S: Into<String>>(self, value: S) -> CookieSession
pub fn name<S: Into<String>>(self, value: S) -> CookieSession
Sets the name
field in the session cookie being built.
sourcepub fn domain<S: Into<String>>(self, value: S) -> CookieSession
pub fn domain<S: Into<String>>(self, value: S) -> CookieSession
Sets the domain
field in the session cookie being built.
sourcepub fn lazy(self, value: bool) -> CookieSession
pub fn lazy(self, value: bool) -> CookieSession
When true, prevents adding session cookies to responses until
the session contains data. Default is false
.
Useful when trying to comply with laws that require consent for setting cookies.
sourcepub fn secure(self, value: bool) -> CookieSession
pub fn secure(self, value: bool) -> CookieSession
Sets the secure
field in the session cookie being built.
If the secure
field is set, a cookie will only be transmitted when the
connection is secure - i.e. https
sourcepub fn http_only(self, value: bool) -> CookieSession
pub fn http_only(self, value: bool) -> CookieSession
Sets the http_only
field in the session cookie being built.
sourcepub fn same_site(self, value: SameSite) -> CookieSession
pub fn same_site(self, value: SameSite) -> CookieSession
Sets the same_site
field in the session cookie being built.
sourcepub fn max_age(self, seconds: i64) -> CookieSession
pub fn max_age(self, seconds: i64) -> CookieSession
Sets the max-age
field in the session cookie being built.
sourcepub fn max_age_time(self, value: Duration) -> CookieSession
pub fn max_age_time(self, value: Duration) -> CookieSession
Sets the max-age
field in the session cookie being built.
sourcepub fn expires_in(self, seconds: i64) -> CookieSession
pub fn expires_in(self, seconds: i64) -> CookieSession
Sets the expires
field in the session cookie being built.
sourcepub fn expires_in_time(self, value: Duration) -> CookieSession
pub fn expires_in_time(self, value: Duration) -> CookieSession
Sets the expires
field in the session cookie being built.
Trait Implementations
sourceimpl Clone for CookieSession
impl Clone for CookieSession
sourcefn clone(&self) -> CookieSession
fn clone(&self) -> CookieSession
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<S, B> Transform<S, ServiceRequest> for CookieSession where
S: Service<ServiceRequest, Response = ServiceResponse<B>>,
S::Future: 'static,
S::Error: 'static,
B: MessageBody + 'static,
impl<S, B> Transform<S, ServiceRequest> for CookieSession where
S: Service<ServiceRequest, Response = ServiceResponse<B>>,
S::Future: 'static,
S::Error: 'static,
B: MessageBody + 'static,
type Response = ServiceResponse<EitherBody<B>>
type Response = ServiceResponse<EitherBody<B>>
Responses produced by the service.
type Error = S::Error
type Error = S::Error
Errors produced by the service.
type Transform = CookieSessionMiddleware<S>
type Transform = CookieSessionMiddleware<S>
The TransformService
value created by this factory
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations
impl RefUnwindSafe for CookieSession
impl !Send for CookieSession
impl !Sync for CookieSession
impl Unpin for CookieSession
impl UnwindSafe for CookieSession
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more