Struct cookie::CookieJar [] [src]

pub struct CookieJar<'a> {
    // some fields omitted
}

A jar of cookies for managing a session

Example

use cookie::{Cookie, CookieJar};

let c = CookieJar::new(b"f8f9eaf1ecdedff5e5b749c58115441e");

// Add a cookie to this jar
c.add(Cookie::new("key".to_string(), "value".to_string()));

// Remove the added cookie
c.remove("key");

Methods

impl<'a> CookieJar<'a>
[src]

fn new(key: &[u8]) -> CookieJar<'static>

Creates a new empty cookie jar with the given signing key.

The given key is used to sign cookies in the signed cookie jar.

fn add_original(&mut self, cookie: Cookie)

Adds an original cookie from a request.

This method only works on the root cookie jar and is not intended for use during the lifetime of a request, it is intended to initialize a cookie jar from an incoming request.

fn add(&self, cookie: Cookie)

Adds a new cookie to this cookie jar.

If this jar is a child cookie jar, this will walk up the chain of borrowed jars, modifying the cookie as it goes along.

fn remove(&self, cookie: &str)

Removes a cookie from this cookie jar.

fn find(&self, name: &str) -> Option<Cookie>

Finds a cookie inside of this cookie jar.

The cookie is subject to modification by any of the child cookie jars that are currently borrowed. A copy of the cookie is returned.

fn signed<'b>(&'b self) -> CookieJar<'b>

Creates a child signed cookie jar.

All cookies read from the child jar will require a valid signature and all cookies written will be signed automatically.

Example

let c = CookieJar::new(b"f8f9eaf1ecdedff5e5b749c58115441e");

// Add a signed cookie to the jar
c.signed().add(Cookie::new("key".to_string(), "value".to_string()));

// Add a permanently signed cookie to the jar
c.permanent().signed()
 .add(Cookie::new("key".to_string(), "value".to_string()));

fn encrypted<'b>(&'b self) -> CookieJar<'b>

Creates a child encrypted cookie jar.

All cookies read from the child jar must be encrypted and signed by a valid key and all cookies written will be encrypted and signed automatically.

Example

let c = CookieJar::new(b"f8f9eaf1ecdedff5e5b749c58115441e");

// Add a signed and encrypted cookie to the jar
c.encrypted().add(Cookie::new("key".to_string(), "value".to_string()));

// Add a permanently signed and encrypted cookie to the jar
c.permanent().encrypted()
 .add(Cookie::new("key".to_string(), "value".to_string()));

fn permanent<'b>(&'b self) -> CookieJar<'b>

Creates a child jar for permanent cookie storage.

All cookies written to the child jar will have an expiration date 20 years into the future to ensure they stick around for a long time.

fn delta(&self) -> Vec<Cookie>

Calculates the changes that have occurred to this cookie jar over time, returning a vector of Set-Cookie headers.

fn iter(&self) -> Iter

Return an iterator over the cookies in this jar.

This iterator will only yield valid cookies for this jar. For example if this is an encrypted child jar then only valid encrypted cookies will be yielded. If the root cookie jar is iterated over then all cookies will be yielded.