Struct insta::CookieStore

pub struct CookieStore { /* private fields */ }
Expand description

An implementation for storing and retrieving [Cookie]s per the path and domain matching rules specified in RFC6265.

Implementations§

§

impl CookieStore

pub fn get_request_cookies( &self, url: &Url ) -> impl Iterator<Item = &Cookie<'static>>

👎Deprecated since 0.14.1: Please use the get_request_values function instead

Return an Iterator of the cookies for url in the store, suitable for submitting in an HTTP request. As the items are intended for use in creating a Cookie header in a GET request, they may contain only the name and value of a received cookie, eliding other parameters such as path or expires. For iteration over Cookie instances containing all data, please refer to CookieStore::matches.

pub fn get_request_values( &self, url: &Url ) -> impl Iterator<Item = (&str, &str)>

Return an Iterator of the cookie (name, value) pairs for url in the store, suitable for use in the Cookie header of an HTTP request. For iteration over Cookie instances, please refer to CookieStore::matches.

pub fn store_response_cookies<I>(&mut self, cookies: I, url: &Url)where I: Iterator<Item = Cookie<'static>>,

Store the cookies received from url

pub fn with_suffix_list(self, psl: List) -> CookieStore

Specify a publicsuffix::List for the CookieStore to allow public suffix matching

pub fn contains(&self, domain: &str, path: &str, name: &str) -> bool

Returns true if the CookieStore contains an unexpired Cookie corresponding to the specified domain, path, and name.

pub fn contains_any(&self, domain: &str, path: &str, name: &str) -> bool

Returns true if the CookieStore contains any (even an expired) Cookie corresponding to the specified domain, path, and name.

pub fn get(&self, domain: &str, path: &str, name: &str) -> Option<&Cookie<'_>>

Returns a reference to the unexpired Cookie corresponding to the specified domain, path, and name.

pub fn get_any( &self, domain: &str, path: &str, name: &str ) -> Option<&Cookie<'static>>

Returns a reference to the (possibly expired) Cookie corresponding to the specified domain, path, and name.

pub fn remove( &mut self, domain: &str, path: &str, name: &str ) -> Option<Cookie<'static>>

Removes a Cookie from the store, returning the Cookie if it was in the store

pub fn matches(&self, request_url: &Url) -> Vec<&Cookie<'static>>

Returns a collection of references to unexpired cookies that path- and domain-match request_url, as well as having HttpOnly and Secure attributes compatible with the request_url.

pub fn parse( &mut self, cookie_str: &str, request_url: &Url ) -> Result<StoreAction, Error>

Parses a new Cookie from cookie_str and inserts it into the store.

pub fn insert_raw( &mut self, cookie: &Cookie<'_>, request_url: &Url ) -> Result<StoreAction, Error>

Converts a cookie::Cookie (from the cookie crate) into a cookie_store::Cookie and inserts it into the store.

pub fn insert( &mut self, cookie: Cookie<'static>, request_url: &Url ) -> Result<StoreAction, Error>

Inserts cookie, received from request_url, into the store, following the rules of the IETF RFC6265 Storage Model. If the Cookie is unexpired and is successfully inserted, returns Ok(StoreAction::Inserted). If the Cookie is expired and matches an existing Cookie in the store, the existing Cookie wil be expired() and Ok(StoreAction::ExpiredExisting) will be returned.

pub fn clear(&mut self)

Clear the contents of the store

pub fn iter_unexpired<'a>( &'a self ) -> impl Iterator<Item = &'a Cookie<'static>> + 'a

An iterator visiting all the unexpired cookies in the store

pub fn iter_any<'a>(&'a self) -> impl Iterator<Item = &'a Cookie<'static>> + 'a

An iterator visiting all (including expired) cookies in the store

pub fn save<W, E, F>( &self, writer: &mut W, cookie_to_string: F ) -> Result<(), Box<dyn Error + Send + Sync>>where W: Write, F: Fn(&Cookie<'static>) -> Result<String, E>, Box<dyn Error + Send + Sync>: From<E>,

Serialize any unexpired and persistent cookies in the store with cookie_to_string and write them to writer

pub fn save_json<W>( &self, writer: &mut W ) -> Result<(), Box<dyn Error + Send + Sync>>where W: Write,

Serialize any unexpired and persistent cookies in the store to JSON format and write them to writer

pub fn save_incl_expired_and_nonpersistent<W, E, F>( &self, writer: &mut W, cookie_to_string: F ) -> Result<(), Box<dyn Error + Send + Sync>>where W: Write, F: Fn(&Cookie<'static>) -> Result<String, E>, Box<dyn Error + Send + Sync>: From<E>,

Serialize all (including expired and non-persistent) cookies in the store with cookie_to_string and write them to writer

pub fn save_incl_expired_and_nonpersistent_json<W>( &self, writer: &mut W ) -> Result<(), Box<dyn Error + Send + Sync>>where W: Write,

Serialize all (including expired and non-persistent) cookies in the store to JSON format and write them to writer

pub fn load<R, E, F>( reader: R, cookie_from_str: F ) -> Result<CookieStore, Box<dyn Error + Send + Sync>>where R: BufRead, F: Fn(&str) -> Result<Cookie<'static>, E>, Box<dyn Error + Send + Sync>: From<E>,

Load cookies from reader, deserializing with cookie_from_str, skipping any expired cookies

pub fn load_all<R, E, F>( reader: R, cookie_from_str: F ) -> Result<CookieStore, Box<dyn Error + Send + Sync>>where R: BufRead, F: Fn(&str) -> Result<Cookie<'static>, E>, Box<dyn Error + Send + Sync>: From<E>,

Load cookies from reader, deserializing with cookie_from_str, loading both unexpired and expired cookies

pub fn load_json<R>( reader: R ) -> Result<CookieStore, Box<dyn Error + Send + Sync>>where R: BufRead,

Load JSON-formatted cookies from reader, skipping any expired cookies

pub fn load_json_all<R>( reader: R ) -> Result<CookieStore, Box<dyn Error + Send + Sync>>where R: BufRead,

Load JSON-formatted cookies from reader, loading both expired and unexpired cookies

pub fn from_cookies<I, E>( iter: I, include_expired: bool ) -> Result<CookieStore, E>where I: IntoIterator<Item = Result<Cookie<'static>, E>>,

Create a CookieStore from an iterator of Cookie values. When include_expired is true, both expired and unexpired cookies in the incoming iterator will be included in the produced CookieStore; otherwise, only unexpired cookies will be included, and expired cookies filtered out.

pub fn new(public_suffix_list: Option<List>) -> CookieStore

Trait Implementations§

§

impl Clone for CookieStore

§

fn clone(&self) -> CookieStore

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
§

impl Debug for CookieStore

§

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

Formats the value using the given formatter. Read more
§

impl Default for CookieStore

§

fn default() -> CookieStore

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

impl<'de> Deserialize<'de> for CookieStore

§

fn deserialize<D>( deserializer: D ) -> Result<CookieStore, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Serialize for CookieStore

§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere 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 Twhere 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 Twhere 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,