pub struct CookieContext<S>(/* private fields */);Expand description
Manages server-side sessions identified by a cookie.
Construct with CookieContext::builder. Use as a Tower Layer
to load sessions from incoming requests, then extract CookieSession<S> in handlers.
Also implements FromRequestParts (via FromRef) so you can extract it
in handlers to create or remove sessions.
Implementations§
Source§impl CookieContext<()>
impl CookieContext<()>
Sourcepub fn builder() -> CookieSessionBuilder<()>
pub fn builder() -> CookieSessionBuilder<()>
Create a CookieSessionBuilder to configure the session store and cookie options.
Source§impl<S: 'static> CookieContext<S>
impl<S: 'static> CookieContext<S>
Build a cookie for the given session ID using the configured cookie options.
Sourcepub async fn create_session(&self, state: S) -> Result<Cookie, Response>
pub async fn create_session(&self, state: S) -> Result<Cookie, Response>
Create a new session, store it, and return a Set-Cookie cookie.
Sourcepub async fn remove_session_jar(
&self,
jar: &CookieJar,
) -> Result<Option<CookieSession<S>>, Response>
pub async fn remove_session_jar( &self, jar: &CookieJar, ) -> Result<Option<CookieSession<S>>, Response>
Remove the session identified by the cookie in the given jar.
Remove the session identified by the given cookie.
Sourcepub async fn remove_session(
&self,
session_id: &SessionId,
) -> Result<Option<CookieSession<S>>, Response>
pub async fn remove_session( &self, session_id: &SessionId, ) -> Result<Option<CookieSession<S>>, Response>
Remove the session with the given ID from the store.
Create a cookie builder with the configured options and a custom name.
Return a reference to the underlying cookie builder.
Sourcepub async fn remove_before(&self, deadline: u64) -> Result<(), Response>
pub async fn remove_before(&self, deadline: u64) -> Result<(), Response>
Remove all sessions created before deadline (Unix timestamp in seconds).
Load a session from the store using a cookie’s value as the session ID.