pub struct RequestCookies<'c> { /* private fields */ }
Expand description

A collection of RequestCookies attached to an HTTP request using the Cookie header.

Implementations§

source§

impl<'c> RequestCookies<'c>

source

pub fn new() -> RequestCookies<'c>

Creates a new, empty RequestCookies map.

source

pub fn append<C>(&mut self, cookie: C) -> bool
where C: Into<RequestCookie<'c>>,

Inserts a new RequestCookie into self.

If a cookie with the same name already exists, the new value is appended to the existing value list.

If you want to replace the existing value list for a given name, use the RequestCookies::replace() method.

§Return value

Returns true if RequestCookies contained one or more cookies with the same name. false otherwise.

§Example
use biscotti::{RequestCookie, RequestCookies};

let mut cookies = RequestCookies::new();
cookies.append(RequestCookie::new("name", "value1"));
assert_eq!(cookies.get("name").unwrap().value(), "value1");

// A new cookie with the same name: its value is appended to
// the existing value list for `name`.
cookies.append(RequestCookie::new("name", "value2"));
// `get` keeps returning the first value.
assert_eq!(cookies.get("name").unwrap().value(), "value1");
// Use `get_all` to get all values for a given name.
let mut c = cookies.get_all("name").unwrap();
assert_eq!(c.next().unwrap().value(), "value1");
assert_eq!(c.next().unwrap().value(), "value2");
assert_eq!(c.next(), None);
source

pub fn replace<C>(&mut self, cookie: C) -> bool
where C: Into<RequestCookie<'c>>,

Inserts a new RequestCookie into self.

If a cookie with the same name already exists, the existing value list is discarded and replaced with the new value.

If you want to append a new value to the existing value list, use RequestCookies::append().

§Return value

Returns true if RequestCookies contained one or more cookies with the same name. false otherwise.

§Example
use biscotti::{RequestCookie, RequestCookies};

let mut cookies = RequestCookies::new();
cookies.replace(RequestCookie::new("name", "value1"));

assert_eq!(cookies.get("name").unwrap().value(), "value1");

// A new cookie with the same name: its value replaces
// the existing value list for `name`.
cookies.replace(RequestCookie::new("name", "value2"));

assert_eq!(cookies.get("name").unwrap().value(), "value2");
let mut values = cookies.get_all("name").unwrap().values();
assert_eq!(values.next(), Some("value2"));
assert_eq!(values.next(), None);
source

pub fn get(&self, name: &str) -> Option<RequestCookie<'c>>

Get a cookie by name.

If there are multiple cookie values associated to the name, this method returns the first one. If you want to get all cookie values for a given name, use RequestCookies::get_all().

§Example
use biscotti::{RequestCookie, RequestCookies};

let mut cookies = RequestCookies::new();
cookies.append(RequestCookie::new("name", "value1"));
assert_eq!(cookies.get("name").unwrap().value(), "value1");

// A new cookie with the same name: its value is appended to
// the existing value list for `name`.
cookies.append(RequestCookie::new("name", "value2"));

// `get` keeps returning the first value.
assert_eq!(cookies.get("name").unwrap().value(), "value1");
// `get_all` returns all values.
let mut values = cookies.get_all("name").unwrap().values();
assert_eq!(values.next(), Some("value1"));
assert_eq!(values.next(), Some("value2"));
assert_eq!(values.next(), None);
source

pub fn get_all(&self, name: &str) -> Option<CookiesForName<'_, 'c>>

Get all cookie values for a given cookie name.
If there are no cookies with the given name, the method returns None.

If you want to get the first cookie value for a given name, use the RequestCookies::get() method.

§Example
use biscotti::{RequestCookie, RequestCookies};

let mut cookies = RequestCookies::new();
cookies.append(RequestCookie::new("name", "value1"));
assert_eq!(cookies.get("name").unwrap().value(), "value1");

// A new cookie with the same name: its value is appended to
// the existing value list for `name`.
cookies.append(RequestCookie::new("name", "value2"));

// `get` keeps returning the first value.
assert_eq!(cookies.get("name").unwrap().value(), "value1");
// `get_all` returns all values.
let mut values = cookies.get_all("name").unwrap().values();
assert_eq!(values.next(), Some("value1"));
assert_eq!(values.next(), Some("value2"));
assert_eq!(values.next(), None);
source

pub fn parse_header( header: &'c str, policy: &Processor ) -> Result<RequestCookies<'c>, ParseError>

Parse a Cookie header value into a RequestCookies map.

Trait Implementations§

source§

impl<'c> Clone for RequestCookies<'c>

source§

fn clone(&self) -> RequestCookies<'c>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'c> Debug for RequestCookies<'c>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'c> Default for RequestCookies<'c>

source§

fn default() -> RequestCookies<'c>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for RequestCookies<'c>

§

impl<'c> Send for RequestCookies<'c>

§

impl<'c> Sync for RequestCookies<'c>

§

impl<'c> Unpin for RequestCookies<'c>

§

impl<'c> UnwindSafe for RequestCookies<'c>

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V