pub struct CookieConfig {
    pub name: String,
    pub same_site: SameSite,
    pub max_age: Option<Duration>,
    pub secure: bool,
    pub path: String,
    pub domain: Option<String>,
}
Expand description

Defines the configuration for the cookie belonging to the session.

Fields§

§name: String

The name of the cookie.

§same_site: SameSite

Specifies the SameSite attribute of the cookie.

The SameSite attribute restricts when cookies are sent to the server, helping to protect against certain types of cross-site request forgery (CSRF) attacks.

  • SameSite::Strict: The cookie is only sent when making a “same-site” request, which includes requests originating from the same site as the cookie.
  • SameSite::Lax: The cookie is sent on “same-site” requests as well as during safe “cross-site” top-level navigations (e.g., clicking a link).
  • SameSite::None: The cookie is sent on all requests, regardless of origin.
§max_age: Option<Duration>

Specifies the maximum age of the cookie.

This field represents the duration for which the cookie is considered valid before it expires. If set to None, the cookie will be treated as a session cookie and will expire when the browser is closed.

§secure: bool

Indicates whether the cookie should only be transmitted over secure (HTTPS) connections.

If true, the cookie will only be sent to the server over secure connections. If false, the cookie may be sent over both secure and non-secure connections.

§path: String

Specifies the path for which the cookie is valid.

The cookie will only be sent to the server when the request path matches or is a subpath of the path specified here.

§domain: Option<String>

Specifies the domain for which the cookie is valid.

If Some, the cookie is only sent to the server when the request domain matches the specified domain. If None, the cookie is valid for the current domain.

Implementations§

source§

impl CookieConfig

Create a Cookie from the provided Session.

Examples
use tower_sessions::{CookieConfig, Session};
let session = Session::new();
let cookie_config = CookieConfig::default();
let cookie = cookie_config.build_cookie(&session);
assert_eq!(cookie.value(), session.id().to_string());

Trait Implementations§

source§

impl Clone for CookieConfig

source§

fn clone(&self) -> CookieConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CookieConfig

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for CookieConfig

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<&CookieConfig> for Session

source§

fn from(cookie_config: &CookieConfig) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for Twhere T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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