Struct cookie::prefix::PrefixedJar
source · pub struct PrefixedJar<P: Prefix, J> {
parent: J,
_prefix: PhantomData<fn() -> P>,
}
Expand description
A child jar that automatically prefixes cookies.
Obtained via CookieJar::prefixed()
and CookieJar::prefixed_mut()
.
This jar implements the HTTP RFC6265 draft “cookie prefixes” extension by
automatically adding and removing a specified Prefix
from cookies that
are added and retrieved from this jar, respectively. Additionally, upon
being added to this jar, cookies are automatically made to
conform to the corresponding prefix’s specifications.
Note: Cookie prefixes are specified in an HTTP draft! Their meaning and definition are subject to change.
Fields§
§parent: J
§_prefix: PhantomData<fn() -> P>
Implementations§
source§impl<P: Prefix, J: Borrow<CookieJar>> PrefixedJar<P, J>
impl<P: Prefix, J: Borrow<CookieJar>> PrefixedJar<P, J>
sourcepub fn get(&self, name: &str) -> Option<Cookie<'static>>
pub fn get(&self, name: &str) -> Option<Cookie<'static>>
Fetches the Cookie
inside this jar with the prefix P
and removes the
prefix before returning it. If the cookie isn’t found, returns None
.
See CookieJar::prefixed()
for more examples.
§Example
use cookie::CookieJar;
use cookie::prefix::{Host, Secure};
// Add a `Host` prefixed cookie.
let mut jar = CookieJar::new();
jar.prefixed_mut(Host).add(("h0st", "value"));
assert_eq!(jar.prefixed(Host).get("h0st").unwrap().name(), "h0st");
assert_eq!(jar.prefixed(Host).get("h0st").unwrap().value(), "value");
source§impl<P: Prefix, J: BorrowMut<CookieJar>> PrefixedJar<P, J>
impl<P: Prefix, J: BorrowMut<CookieJar>> PrefixedJar<P, J>
sourcepub fn add<C: Into<Cookie<'static>>>(&mut self, cookie: C)
pub fn add<C: Into<Cookie<'static>>>(&mut self, cookie: C)
Adds cookie
to the parent jar. The cookie’s name is prefixed with P
,
and the cookie’s attributes are made to conform
.
See CookieJar::prefixed_mut()
for more examples.
§Example
use cookie::{Cookie, CookieJar};
use cookie::prefix::{Host, Secure};
// Add a `Host` prefixed cookie.
let mut jar = CookieJar::new();
jar.prefixed_mut(Secure).add(Cookie::build(("name", "value")).secure(false));
assert_eq!(jar.prefixed(Secure).get("name").unwrap().value(), "value");
assert_eq!(jar.prefixed(Secure).get("name").unwrap().secure(), Some(true));
sourcepub fn add_original<C: Into<Cookie<'static>>>(&mut self, cookie: C)
pub fn add_original<C: Into<Cookie<'static>>>(&mut self, cookie: C)
Adds cookie
to the parent jar. The cookie’s name is prefixed with P
,
and the cookie’s attributes are made to conform
.
Adding an original cookie does not affect the CookieJar::delta()
computation. This method is intended to be used to seed the cookie jar
with cookies. For accurate delta
computations, this method should not
be called after calling remove
.
§Example
use cookie::{Cookie, CookieJar};
use cookie::prefix::{Host, Secure};
// Add a `Host` prefixed cookie.
let mut jar = CookieJar::new();
jar.prefixed_mut(Secure).add_original(("name", "value"));
assert_eq!(jar.iter().count(), 1);
assert_eq!(jar.delta().count(), 0);
sourcepub fn remove<C: Into<Cookie<'static>>>(&mut self, cookie: C)
pub fn remove<C: Into<Cookie<'static>>>(&mut self, cookie: C)
Removes cookie
from the parent jar.
The cookie’s name is prefixed with P
, and the cookie’s attributes are
made to conform
before attempting to remove the
cookie. For correct removal, the passed in cookie
must contain the
same path
and domain
as the cookie that was initially set.
§Example
use cookie::{Cookie, CookieJar};
use cookie::prefix::{Host, Secure};
let mut jar = CookieJar::new();
let mut prefixed_jar = jar.prefixed_mut(Host);
prefixed_jar.add(("name", "value"));
assert!(prefixed_jar.get("name").is_some());
prefixed_jar.remove("name");
assert!(prefixed_jar.get("name").is_none());