[−][src]Struct cookie_store::Cookie
A cookie conforming more closely to IETF RFC6265
Fields
path: CookiePathThe Path attribute from a Set-Cookie header or the default-path as determined from the request-uri
domain: CookieDomainThe Domain attribute from a Set-Cookie header, or a HostOnly variant if no non-empty Domain attribute found
expires: CookieExpirationFor a persistent Cookie (see IETF RFC6265 Section
5.3),
the expiration time as defined by the Max-Age or Expires attribute,
otherwise SessionEnd,
indicating a non-persistent Cookie that should expire at the end of the
session
Methods
impl<'a> Cookie<'a>[src]
pub fn matches(&self, request_url: &Url) -> bool[src]
Whether this Cookie should be included for request_url
pub fn is_persistent(&self) -> bool[src]
Should this Cookie be persisted across sessions?
pub fn expire(&mut self)[src]
Expire this cookie
pub fn is_expired(&self) -> bool[src]
Return whether the Cookie is expired now
pub fn expires_by(&self, utc_tm: &Tm) -> bool[src]
Indicates if the Cookie expires as of utc_tm.
pub fn parse<S>(cookie_str: S, request_url: &Url) -> CookieResult<'a> where
S: Into<Cow<'a, str>>, [src]
S: Into<Cow<'a, str>>,
Parses a new user_agent::Cookie from cookie_str.
pub fn try_from_raw_cookie(
raw_cookie: &RawCookie<'a>,
request_url: &Url
) -> CookieResult<'a>[src]
raw_cookie: &RawCookie<'a>,
request_url: &Url
) -> CookieResult<'a>
Create a new user_agent::Cookie from a cookie::Cookie (from the cookie crate)
received from request_url.
pub fn into_owned(self) -> Cookie<'static>[src]
Methods from Deref<Target = RawCookie<'a>>
pub fn encoded(&'a self) -> EncodedCookie<'a, 'c>[src]
Wraps self in an EncodedCookie: a cost-free wrapper around Cookie
whose Display implementation percent-encodes the name and value of the
wrapped Cookie.
This method is only available when the percent-encode feature is
enabled.
Example
use cookie::Cookie; let mut c = Cookie::new("my name", "this; value?"); assert_eq!(&c.encoded().to_string(), "my%20name=this%3B%20value%3F");
pub fn name(&self) -> &str[src]
Returns the name of self.
Example
use cookie::Cookie; let c = Cookie::new("name", "value"); assert_eq!(c.name(), "name");
pub fn value(&self) -> &str[src]
Returns the value of self.
Example
use cookie::Cookie; let c = Cookie::new("name", "value"); assert_eq!(c.value(), "value");
pub fn name_value(&self) -> (&str, &str)[src]
Returns the name and value of self as a tuple of (name, value).
Example
use cookie::Cookie; let c = Cookie::new("name", "value"); assert_eq!(c.name_value(), ("name", "value"));
pub fn http_only(&self) -> Option<bool>[src]
Returns whether this cookie was marked HttpOnly or not. Returns
Some(true) when the cookie was explicitly set (manually or parsed) as
HttpOnly, Some(false) when http_only was manually set to false,
and None otherwise.
Example
use cookie::Cookie; let c = Cookie::parse("name=value; httponly").unwrap(); assert_eq!(c.http_only(), Some(true)); let mut c = Cookie::new("name", "value"); assert_eq!(c.http_only(), None); let mut c = Cookie::new("name", "value"); assert_eq!(c.http_only(), None); // An explicitly set "false" value. c.set_http_only(false); assert_eq!(c.http_only(), Some(false)); // An explicitly set "true" value. c.set_http_only(true); assert_eq!(c.http_only(), Some(true));
pub fn secure(&self) -> Option<bool>[src]
Returns whether this cookie was marked Secure or not. Returns
Some(true) when the cookie was explicitly set (manually or parsed) as
Secure, Some(false) when secure was manually set to false, and
None otherwise.
Example
use cookie::Cookie; let c = Cookie::parse("name=value; Secure").unwrap(); assert_eq!(c.secure(), Some(true)); let mut c = Cookie::parse("name=value").unwrap(); assert_eq!(c.secure(), None); let mut c = Cookie::new("name", "value"); assert_eq!(c.secure(), None); // An explicitly set "false" value. c.set_secure(false); assert_eq!(c.secure(), Some(false)); // An explicitly set "true" value. c.set_secure(true); assert_eq!(c.secure(), Some(true));
pub fn same_site(&self) -> Option<SameSite>[src]
Returns the SameSite attribute of this cookie if one was specified.
Example
use cookie::{Cookie, SameSite}; let c = Cookie::parse("name=value; SameSite=Lax").unwrap(); assert_eq!(c.same_site(), Some(SameSite::Lax));
pub fn max_age(&self) -> Option<Duration>[src]
Returns the specified max-age of the cookie if one was specified.
Example
use cookie::Cookie; let c = Cookie::parse("name=value").unwrap(); assert_eq!(c.max_age(), None); let c = Cookie::parse("name=value; Max-Age=3600").unwrap(); assert_eq!(c.max_age().map(|age| age.num_hours()), Some(1));
pub fn path(&self) -> Option<&str>[src]
Returns the Path of the cookie if one was specified.
Example
use cookie::Cookie; let c = Cookie::parse("name=value").unwrap(); assert_eq!(c.path(), None); let c = Cookie::parse("name=value; Path=/").unwrap(); assert_eq!(c.path(), Some("/")); let c = Cookie::parse("name=value; path=/sub").unwrap(); assert_eq!(c.path(), Some("/sub"));
pub fn domain(&self) -> Option<&str>[src]
Returns the Domain of the cookie if one was specified.
Example
use cookie::Cookie; let c = Cookie::parse("name=value").unwrap(); assert_eq!(c.domain(), None); let c = Cookie::parse("name=value; Domain=crates.io").unwrap(); assert_eq!(c.domain(), Some("crates.io"));
pub fn expires(&self) -> Option<Tm>[src]
Returns the Expires time of the cookie if one was specified.
Example
use cookie::Cookie; let c = Cookie::parse("name=value").unwrap(); assert_eq!(c.expires(), None); let expire_time = "Wed, 21 Oct 2017 07:28:00 GMT"; let cookie_str = format!("name=value; Expires={}", expire_time); let c = Cookie::parse(cookie_str).unwrap(); assert_eq!(c.expires().map(|t| t.tm_year), Some(117));
pub fn name_raw(&self) -> Option<&'c str>[src]
Returns the name of self as a string slice of the raw string self
was originally parsed from. If self was not originally parsed from a
raw string, returns None.
This method differs from name in that it returns a
string with the same lifetime as the originally parsed string. This
lifetime may outlive self. If a longer lifetime is not required, or
you're unsure if you need a longer lifetime, use name.
Example
use cookie::Cookie; let cookie_string = format!("{}={}", "foo", "bar"); // `c` will be dropped at the end of the scope, but `name` will live on let name = { let c = Cookie::parse(cookie_string.as_str()).unwrap(); c.name_raw() }; assert_eq!(name, Some("foo"));
pub fn value_raw(&self) -> Option<&'c str>[src]
Returns the value of self as a string slice of the raw string self
was originally parsed from. If self was not originally parsed from a
raw string, returns None.
This method differs from value in that it returns a
string with the same lifetime as the originally parsed string. This
lifetime may outlive self. If a longer lifetime is not required, or
you're unsure if you need a longer lifetime, use value.
Example
use cookie::Cookie; let cookie_string = format!("{}={}", "foo", "bar"); // `c` will be dropped at the end of the scope, but `value` will live on let value = { let c = Cookie::parse(cookie_string.as_str()).unwrap(); c.value_raw() }; assert_eq!(value, Some("bar"));
pub fn path_raw(&self) -> Option<&'c str>[src]
Returns the Path of self as a string slice of the raw string self
was originally parsed from. If self was not originally parsed from a
raw string, or if self doesn't contain a Path, or if the Path has
changed since parsing, returns None.
This method differs from path in that it returns a
string with the same lifetime as the originally parsed string. This
lifetime may outlive self. If a longer lifetime is not required, or
you're unsure if you need a longer lifetime, use path.
Example
use cookie::Cookie; let cookie_string = format!("{}={}; Path=/", "foo", "bar"); // `c` will be dropped at the end of the scope, but `path` will live on let path = { let c = Cookie::parse(cookie_string.as_str()).unwrap(); c.path_raw() }; assert_eq!(path, Some("/"));
pub fn domain_raw(&self) -> Option<&'c str>[src]
Returns the Domain of self as a string slice of the raw string
self was originally parsed from. If self was not originally parsed
from a raw string, or if self doesn't contain a Domain, or if the
Domain has changed since parsing, returns None.
This method differs from domain in that it returns a
string with the same lifetime as the originally parsed string. This
lifetime may outlive self struct. If a longer lifetime is not
required, or you're unsure if you need a longer lifetime, use
domain.
Example
use cookie::Cookie; let cookie_string = format!("{}={}; Domain=crates.io", "foo", "bar"); //`c` will be dropped at the end of the scope, but `domain` will live on let domain = { let c = Cookie::parse(cookie_string.as_str()).unwrap(); c.domain_raw() }; assert_eq!(domain, Some("crates.io"));
Trait Implementations
impl<'a> Clone for Cookie<'a>[src]
fn clone(&self) -> Cookie<'a>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<'a> PartialEq<Cookie<'a>> for Cookie<'a>[src]
impl<'a> From<Cookie<'a>> for RawCookie<'a>[src]
impl<'a> Deref for Cookie<'a>[src]
type Target = RawCookie<'a>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target[src]
impl<'a> Debug for Cookie<'a>[src]
impl<'a> Serialize for Cookie<'a>[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer, [src]
__S: Serializer,
impl<'de, 'a> Deserialize<'de> for Cookie<'a>[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>, [src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<'a> Unpin for Cookie<'a>
impl<'a> Sync for Cookie<'a>
impl<'a> Send for Cookie<'a>
impl<'a> UnwindSafe for Cookie<'a>
impl<'a> RefUnwindSafe for Cookie<'a>
Blanket Implementations
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>, [src]
T: Deserialize<'de>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,