pub struct Cookie { /* private fields */ }Expand description
An HTTP Cookie.
Implementations§
Source§impl Cookie
impl Cookie
Sourcepub fn expires_time(&self) -> Option<OffsetDateTime>
pub fn expires_time(&self) -> Option<OffsetDateTime>
Returns the Expires attribute using a OffsetDateTime.
Sourcepub fn max_age_time(&self) -> Option<Duration>
pub fn max_age_time(&self) -> Option<Duration>
Returns the Max-Age attribute using a Duration.
Source§impl Cookie
impl Cookie
Sourcepub fn expires_chrono(&self) -> Option<DateTime<Utc>>
pub fn expires_chrono(&self) -> Option<DateTime<Utc>>
Returns the Expires attribute using chrono::DateTime.
Sourcepub fn max_age_chrono(&self) -> Option<Duration>
pub fn max_age_chrono(&self) -> Option<Duration>
Returns the Max-Age attribute using chrono::Duration.
Source§impl Cookie
impl Cookie
Sourcepub fn expires_jiff(&self) -> Option<&Zoned>
pub fn expires_jiff(&self) -> Option<&Zoned>
Returns the Expires attribute using a Zoned.
Sourcepub fn max_age_jiff(&self) -> Option<SignedDuration>
pub fn max_age_jiff(&self) -> Option<SignedDuration>
Returns the Max-Age attribute using a SignedDuration.
Source§impl Cookie
impl Cookie
Sourcepub fn is_expires_set(&self) -> bool
pub fn is_expires_set(&self) -> bool
If the Expires attribute is not set, the expiration of the cookie is tied to the session with the user-agent.
Source§impl Cookie
impl Cookie
Sourcepub fn new<N, V>(name: N, value: V) -> Cookie
pub fn new<N, V>(name: N, value: V) -> Cookie
Creates a new cookie with the given name and value.
§Example
use cookie_monster::Cookie;
let cookie = Cookie::new("hello", "world");
assert_eq!(cookie.name(), "hello");
assert_eq!(cookie.value(), "world");Sourcepub fn remove<N>(name: N) -> Cookie
pub fn remove<N>(name: N) -> Cookie
Creates a cookie that can be used to remove the cookie from the user-agent. This sets the Expires attribute in the past and Max-Age to 0 seconds.
To ensure a cookie is removed from the user-agent, set the Path and Domain attributes
with the same values that were used to create the cookie.
§Note
You don’t have to use this method with crate::CookieJar::remove, the jar automatically set’s
the Expires and Max-Age attributes.
§Example
use cookie_monster::Cookie;
let cookie = Cookie::remove("session");
assert_eq!(cookie.max_age_secs(), Some(0));
assert!(!cookie.is_expires_set());Sourcepub fn build<N, V>(name: N, value: V) -> CookieBuilder
pub fn build<N, V>(name: N, value: V) -> CookieBuilder
Build a new cookie. This returns a CookieBuilder that can be used to set other attribute
values.
§Example
use cookie_monster::Cookie;
let cookie = Cookie::build("foo", "bar")
.secure()
.http_only()
.build();
assert!(cookie.secure());
assert!(cookie.http_only());Sourcepub fn named<N>(name: N) -> CookieBuilder
pub fn named<N>(name: N) -> CookieBuilder
Creates a CookieBuilder with the given name and an empty value. This can be used when
removing a cookie from a crate::CookieJar.
§Example
use cookie_monster::{Cookie, CookieJar};
let mut jar = CookieJar::empty();
jar.remove(Cookie::named("session").path("/login"));
assert!(jar.get("session").is_none());Sourcepub fn set_expires<E: Into<Expires>>(&mut self, expires: E)
pub fn set_expires<E: Into<Expires>>(&mut self, expires: E)
Set the Expired attribute.
Sourcepub fn max_age(&self) -> Option<Duration>
pub fn max_age(&self) -> Option<Duration>
Get the Max-Age duration. This returns a std::time::Duration, if you’d like a time,
chrono or jiff specific duration use the max_age_{time,chrono,jiff} method.
Sourcepub fn max_age_secs(&self) -> Option<u64>
pub fn max_age_secs(&self) -> Option<u64>
Get the Max-Age as seconds.
Sourcepub fn set_max_age(&mut self, max_age: Duration)
pub fn set_max_age(&mut self, max_age: Duration)
Set the Max-Age attribute.
Sourcepub fn set_max_age_secs(&mut self, max_age_secs: u64)
pub fn set_max_age_secs(&mut self, max_age_secs: u64)
Set the Max-Age value in seconds.
Sourcepub fn unset_max_age(&mut self)
pub fn unset_max_age(&mut self)
Removes the Max-Age attribute.
Sourcepub fn set_domain<D: Into<Cow<'static, str>>>(&mut self, domain: D)
pub fn set_domain<D: Into<Cow<'static, str>>>(&mut self, domain: D)
Set the Domain attribute.
Sourcepub fn unset_domain(&mut self)
pub fn unset_domain(&mut self)
Removes the Domain attribute.
Sourcepub fn unset_path(&mut self)
pub fn unset_path(&mut self)
Removes the path attribute.
Sourcepub fn set_secure(&mut self, secure: bool)
pub fn set_secure(&mut self, secure: bool)
Sets the Secure attribute of the cookie.
Sourcepub fn set_http_only(&mut self, http_only: bool)
pub fn set_http_only(&mut self, http_only: bool)
Sets the HttpOnly attribute of the cookie.
Sourcepub fn partitioned(&self) -> bool
pub fn partitioned(&self) -> bool
Returns if the Partitioned attribute is set.
Sourcepub fn set_partitioned(&mut self, partitioned: bool)
pub fn set_partitioned(&mut self, partitioned: bool)
Set the Partitioned flag, enabling the Partitioned attribute also enables the Secure Attribute.
Sourcepub fn set_same_site<S: Into<Option<SameSite>>>(&mut self, same_site: S)
pub fn set_same_site<S: Into<Option<SameSite>>>(&mut self, same_site: S)
Set the SameSite attribute.