pub struct SessionLayer<Store> { /* private fields */ }

Implementations

Creates a layer which will attach a SessionHandle to requests via an extension. This session is derived from a cryptographically signed cookie. When the client sends a valid, known cookie then the session is hydrated from this. Otherwise a new cookie is created and returned in the response.

Panics

SessionLayer::new will panic if the secret is less than 64 bytes.

Customization

The configuration of the session may be adjusted according to the needs of your application:

SessionLayer::new(
    MemoryStore::new(),
    b"please do not hardcode your secret; instead use a
    cryptographically secure value",
)
.with_cookie_name("your.cookie.name")
.with_cookie_path("/some/path")
.with_cookie_domain("www.example.com")
.with_same_site_policy(SameSite::Lax)
.with_session_ttl(Some(Duration::from_secs(60 * 5)))
.with_save_unchanged(false)
.with_secure(true);

When true, a session cookie will always be set. When false the session data must be modified in order for it to be set. Defaults to true.

Sets a cookie for the session. Defaults to "/".

Sets a cookie name for the session. Defaults to "axum.sid".

Sets a cookie domain for the session. Defaults to None.

Sets a cookie same site policy for the session. Defaults to SameSite::Strict.

Sets a cookie time-to-live (ttl) for the session. Defaults to Duration::from_secs(60 * 60 24); one day.

Sets a cookie secure attribute for the session. Defaults to true.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

The wrapped service

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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