Skip to main content

Cookie

Struct Cookie 

Source
pub struct Cookie {
    pub name: String,
    pub value: String,
    pub domain: Option<String>,
    pub path: Option<String>,
    pub max_age: Option<Duration>,
    pub secure: bool,
    pub http_only: bool,
    pub same_site: Option<SameSite>,
    pub expires_at: Option<Instant>,
}
Expand description

Represents a single HTTP cookie.

Fields§

§name: String§value: String§domain: Option<String>§path: Option<String>§max_age: Option<Duration>

Max-Age attribute stored as a Duration.

§secure: bool§http_only: bool§same_site: Option<SameSite>§expires_at: Option<Instant>

Computed absolute expiry time from max_age, set at insertion.

Implementations§

Source

pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self

Create a new cookie with the given name and value.

Source

pub fn name(&self) -> &str

The cookie name.

Source

pub fn value(&self) -> &str

The cookie value.

Source

pub fn domain(&self) -> Option<&str>

The domain attribute.

Source

pub fn path(&self) -> Option<&str>

The path attribute.

Source

pub fn max_age(&self) -> Option<Duration>

The max-age attribute as a Duration.

Source

pub fn is_secure(&self) -> bool

Whether the Secure flag is set.

Source

pub fn is_http_only(&self) -> bool

Whether the HttpOnly flag is set.

Source

pub fn same_site(&self) -> Option<SameSite>

The SameSite attribute.

Source

pub fn set_domain(self, domain: impl Into<String>) -> Self

Set the domain attribute.

Source

pub fn set_path(self, path: impl Into<String>) -> Self

Set the path attribute.

Source

pub fn set_max_age(self, seconds: u64) -> Self

Set the max-age attribute in seconds.

Source

pub fn set_secure(self, secure: bool) -> Self

Set the Secure flag.

Source

pub fn set_http_only(self, http_only: bool) -> Self

Set the HttpOnly flag.

Source

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

Set the SameSite attribute.

Parse a cookie from a Set-Cookie header value (RFC 6265). expires_at is left as None here; it is computed at insertion time by CookieJar.

Serialize the cookie for use in a Cookie request header.

Trait Implementations§

Source§

fn clone(&self) -> Cookie

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

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

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

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

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

fn eq(&self, other: &Cookie) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.