pub struct Cookie { /* private fields */ }
Expand description
Implements HTTP cookies, as described by RFC 6265.
To have a Session
handle cookies for your appliction
automatically, use a CookieJar
.
@name and @value will be set for all cookies. If the cookie is generated from a string that appears to have no name, then @name will be the empty string.
@domain and @path give the host or domain, and path within that host/domain, to restrict this cookie to. If @domain starts with “.”, that indicates a domain (which matches the string after the “.”, or any hostname that has @domain as a suffix). Otherwise, it is a hostname and must match exactly.
@expires will be non-None
if the cookie uses either the original
“expires” attribute, or the newer “max-age” attribute. If @expires
is None
, it indicates that neither “expires” nor “max-age” was
specified, and the cookie expires at the end of the session.
If @http_only is set, the cookie should not be exposed to untrusted code (eg, javascript), so as to minimize the danger posed by cross-site scripting attacks.
Implementations§
source§impl Cookie
impl Cookie
sourcepub unsafe fn from_glib_ptr_borrow<'a>(
ptr: *const *const SoupCookie
) -> &'a Self
pub unsafe fn from_glib_ptr_borrow<'a>( ptr: *const *const SoupCookie ) -> &'a Self
Borrows the underlying C value.
sourcepub unsafe fn from_glib_ptr_borrow_mut<'a>(
ptr: *mut *mut SoupCookie
) -> &'a mut Self
pub unsafe fn from_glib_ptr_borrow_mut<'a>( ptr: *mut *mut SoupCookie ) -> &'a mut Self
Borrows the underlying C value mutably.
source§impl Cookie
impl Cookie
sourcepub fn new(
name: &str,
value: &str,
domain: &str,
path: &str,
max_age: i32
) -> Cookie
pub fn new( name: &str, value: &str, domain: &str, path: &str, max_age: i32 ) -> Cookie
Creates a new #SoupCookie with the given attributes.
Use set_secure()
and set_http_only()
if you
need to set those attributes on the returned cookie.
If @domain starts with “.”, that indicates a domain (which matches the string after the “.”, or any hostname that has @domain as a suffix). Otherwise, it is a hostname and must match exactly.
@max_age is used to set the “expires” attribute on the cookie; pass
-1 to not include the attribute (indicating that the cookie expires
with the current session), 0 for an already-expired cookie, or a
lifetime in seconds. You can use the constants
SOUP_COOKIE_MAX_AGE_ONE_HOUR
, SOUP_COOKIE_MAX_AGE_ONE_DAY
,
SOUP_COOKIE_MAX_AGE_ONE_WEEK
and SOUP_COOKIE_MAX_AGE_ONE_YEAR
(or
multiples thereof) to calculate this value. (If you really care
about setting the exact time that the cookie will expire, use
set_expires()
.)
As of version 3.4.0 the default value of a cookie’s same-site-policy
is SameSitePolicy::Lax
.
§name
cookie name
§value
cookie value
§domain
cookie domain or hostname
§path
cookie path, or None
§max_age
max age of the cookie, or -1 for a session cookie
§Returns
a new #SoupCookie.
sourcepub fn applies_to_uri(&mut self, uri: &Uri) -> bool
pub fn applies_to_uri(&mut self, uri: &Uri) -> bool
sourcepub fn domain_matches(&mut self, host: &str) -> bool
pub fn domain_matches(&mut self, host: &str) -> bool
sourcepub fn expires(&mut self) -> Option<DateTime>
pub fn expires(&mut self) -> Option<DateTime>
Gets @self’s expiration time.
§Returns
@self’s expiration time, which is owned by @self and should not be modified or freed.
sourcepub fn is_http_only(&mut self) -> bool
pub fn is_http_only(&mut self) -> bool
sourcepub fn same_site_policy(&mut self) -> SameSitePolicy
pub fn same_site_policy(&mut self) -> SameSitePolicy
sourcepub fn set_domain(&mut self, domain: &str)
pub fn set_domain(&mut self, domain: &str)
sourcepub fn set_expires(&mut self, expires: &DateTime)
pub fn set_expires(&mut self, expires: &DateTime)
Sets @self’s expiration time to @expires.
If @expires is None
, @self will be a session cookie and will expire at the
end of the client’s session.
(This sets the same property as set_max_age()
.)
§expires
the new expiration time, or None
sourcepub fn set_http_only(&mut self, http_only: bool)
pub fn set_http_only(&mut self, http_only: bool)
sourcepub fn set_max_age(&mut self, max_age: i32)
pub fn set_max_age(&mut self, max_age: i32)
Sets @self’s max age to @max_age.
If @max_age is -1, the cookie is a session cookie, and will expire at the end
of the client’s session. Otherwise, it is the number of seconds until the
cookie expires. You can use the constants SOUP_COOKIE_MAX_AGE_ONE_HOUR
,
SOUP_COOKIE_MAX_AGE_ONE_DAY
, SOUP_COOKIE_MAX_AGE_ONE_WEEK
and
SOUP_COOKIE_MAX_AGE_ONE_YEAR
(or multiples thereof) to calculate this value.
(A value of 0 indicates that the cookie should be considered
already-expired.)
This sets the same property as set_expires()
.
§max_age
the new max age
sourcepub fn set_same_site_policy(&mut self, policy: SameSitePolicy)
pub fn set_same_site_policy(&mut self, policy: SameSitePolicy)
When used in conjunction with
CookieJarExt::cookie_list_with_same_site_info()
this sets the policy
of when this cookie should be exposed.
§policy
a #SoupSameSitePolicy
sourcepub fn set_secure(&mut self, secure: bool)
pub fn set_secure(&mut self, secure: bool)
sourcepub fn parse(header: &str, origin: Option<&Uri>) -> Option<Cookie>
pub fn parse(header: &str, origin: Option<&Uri>) -> Option<Cookie>
Parses @header and returns a #SoupCookie.
If @header contains multiple cookies, only the first one will be parsed.
If @header does not have “path” or “domain” attributes, they will
be defaulted from @origin. If @origin is None
, path will default
to “/”, but domain will be left as None
. Note that this is not a
valid state for a #SoupCookie, and you will need to fill in some
appropriate string for the domain if you want to actually make use
of the cookie.
As of version 3.4.0 the default value of a cookie’s same-site-policy
is SameSitePolicy::Lax
.
§header
a cookie string (eg, the value of a Set-Cookie header)
§origin
origin of the cookie
§Returns
a new #SoupCookie, or None
if it could
not be parsed, or contained an illegal “domain” attribute for a
cookie originating from @origin.
Trait Implementations§
source§impl HasParamSpec for Cookie
impl HasParamSpec for Cookie
source§impl Ord for Cookie
impl Ord for Cookie
source§impl PartialEq for Cookie
impl PartialEq for Cookie
source§impl PartialOrd for Cookie
impl PartialOrd for Cookie
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl StaticType for Cookie
impl StaticType for Cookie
source§fn static_type() -> Type
fn static_type() -> Type
Self
.