Crate trillium_cookies

source ·
Expand description

§example

use trillium::Conn;
use trillium_cookies::{cookie::Cookie, CookiesConnExt, CookiesHandler};
async fn handler_that_uses_cookies(conn: Conn) -> Conn {
    let content = if let Some(cookie_value) = conn.cookies().get("some_cookie") {
        format!("current cookie value: {}", cookie_value.value())
    } else {
        String::from("no cookie value set")
    };

    conn.with_cookie(("some_cookie", "some-cookie-value")).ok(content)
}

let handler = (CookiesHandler::new(), handler_that_uses_cookies);

use trillium_testing::prelude::*;

assert_ok!(
    get("/").on(&handler),
    "no cookie value set",
    "set-cookie" => "some_cookie=some-cookie-value"
);

assert_ok!(
    get("/").with_request_header("cookie", "some_cookie=trillium").on(&handler),
    "current cookie value: trillium",
    "set-cookie" => "some_cookie=some-cookie-value"
);

Re-exports§

  • pub use cookie;

Structs§

  • The trillium cookie handler. See crate level docs for an example. This must run before any handlers access the cookie jar.

Traits§

Functions§

  • Alias for CookiesHandler::new()