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> PrefixedJar<P, J>

source

pub(crate) fn new(parent: J) -> Self

source§

impl<P: Prefix, J: Borrow<CookieJar>> PrefixedJar<P, J>

source

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>

source

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));
source

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);
source

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());

Auto Trait Implementations§

§

impl<P, J> Freeze for PrefixedJar<P, J>
where J: Freeze,

§

impl<P, J> RefUnwindSafe for PrefixedJar<P, J>
where J: RefUnwindSafe,

§

impl<P, J> Send for PrefixedJar<P, J>
where J: Send,

§

impl<P, J> Sync for PrefixedJar<P, J>
where J: Sync,

§

impl<P, J> Unpin for PrefixedJar<P, J>
where J: Unpin,

§

impl<P, J> UnwindSafe for PrefixedJar<P, J>
where J: UnwindSafe,

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> 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, 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.