Struct CookieOptions

Source
pub struct CookieOptions<'a> {
    pub path: Option<&'a str>,
    pub domain: Option<&'a str>,
    pub expires: Option<Cow<'a, str>>,
    pub secure: bool,
    pub same_site: SameSite,
}
Expand description

Cookies options (see https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie).

You can create it by calling CookieOptions::default().

Fields§

§path: Option<&'a str>

If None, defaults to the current path of the current document location.

§domain: Option<&'a str>

If None, defaults to the host portion of the current document location.

§expires: Option<Cow<'a, str>>

Expiration date in GMT string format. If None, the cookie will expire at the end of session.

§secure: bool

If true, the cookie will only be transmitted over secure protocol as HTTPS. The default value is false.

§same_site: SameSite

SameSite prevents the browser from sending the cookie along with cross-site requests (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#SameSite_attribute).

Implementations§

Source§

impl<'a> CookieOptions<'a>

Source

pub fn with_path(self, path: &'a str) -> Self

Set the path. The default value is the current path of the current document location.

Source

pub fn with_domain(self, domain: &'a str) -> Self

Set the domain. The default value is the host portion of the current document location.

Source

pub fn expires_at_date(self, date: &'a str) -> Self

Expires the cookie at a specific date.

date must be a GMT string (see https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString).

The default behavior of the cookie is to expire at the end of session.

Source

pub fn expires_at_timestamp(self, timestamp: i64) -> Self

Expires the cookie at a specific timestamp (in milliseconds, UTC, with leap seconds ignored). The default behavior of the cookie is to expire at the end of session.

Source

pub fn expires_after(self, duration: Duration) -> Self

Expires the cookie after a certain duration. The default behavior of the cookie is to expire at the end of session.

Source

pub fn secure(self) -> Self

Set the cookie to be only transmitted over secure protocol as HTTPS.

Source

pub fn with_same_site(self, same_site: SameSite) -> Self

Set the SameSite value. SameSite prevents the browser from sending the cookie along with cross-site requests (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#SameSite_attribute).

Trait Implementations§

Source§

impl<'a> Clone for CookieOptions<'a>

Source§

fn clone(&self) -> CookieOptions<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for CookieOptions<'a>

Source§

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

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

impl<'a> Default for CookieOptions<'a>

Source§

fn default() -> CookieOptions<'a>

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

Auto Trait Implementations§

§

impl<'a> Freeze for CookieOptions<'a>

§

impl<'a> RefUnwindSafe for CookieOptions<'a>

§

impl<'a> Send for CookieOptions<'a>

§

impl<'a> Sync for CookieOptions<'a>

§

impl<'a> Unpin for CookieOptions<'a>

§

impl<'a> UnwindSafe for CookieOptions<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.