Cookie

Struct Cookie 

Source
pub struct Cookie { /* private fields */ }
Expand description

Represents a cookie created from Set-Cookie response header.

A Cookie can be parsed from the Set-Cookie value from an HTTP Response using the trait FromStr:

let cookie = Cookie::from_str("id=a3fWa; Expires=Wed, 21 Oct 2022 07:28:00 GMT");

See RFC6265 Set-Cookie for more information.

Implementations§

Source

pub fn new(name: String, value: String, domain: String, path: String) -> Cookie

Constructor. It takes ownership params:

  • name: Cookie name
  • value: Cookie value, for binary data it is recommended Base64 encoding.
  • domain: Cookie domain, sets hosts (domain and subdomains) to which the cookie will be sent, in includes subdomains. If not present in Set-Cookie header, it is taken from the HTTP request Host header
  • path: Cookie path, paths (same path or children) to which the cookie will be sent If not present in Set-Cookie header, it is taken from the HTTP request path
Source

pub fn name(&self) -> &str

Cookie name

Source

pub fn value(&self) -> &str

Cookie value

Source

pub fn domain(&self) -> &str

Cookie domain: hosts to which the cookie will be sent

Source

pub fn path(&self) -> &str

Cookie path

Source

pub fn expires(&self) -> Option<SystemTime>

When the Cookie expires, if None, it does not expire. This value is obtained from Max-Age and Expires attributes (Max-Age has precedence)

Source

pub fn same_site(&self) -> SameSiteValue

Cookie Same-Site value (optional)

Source

pub fn secure(&self) -> bool

Cookie requires HTTPS

Source

pub fn http_only(&self) -> bool

Cookie requires HTTP only

Source

pub fn extensions(&self) -> &HashMap<String, String>

Cookie extendions

Source

pub fn path_match(&self, request_path: &str) -> bool

Checks if the request path match the cookie path.

Using RFC6265 Section 5.1.4 Algorithm.

Source

pub fn domain_match(&self, request_domain: &str) -> bool

Checks if the request domain match the cookie domain.

Using RFC6265 Section 4.1.1.3.

Source

pub fn request_match( &self, request_domain: &str, request_path: &str, secure: bool, ) -> bool

Checks if the cookie can be used on this request

Source

pub fn parse(s: &str, domain: &str, path: &str) -> Result<Cookie, Error>

Parses a cookie value and modifiers from a ’Set-Cookie’header

Trait Implementations§

Source§

fn clone(&self) -> Cookie

Returns a duplicate of the value. Read more
1.0.0 · 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 hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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, 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.