Expand description
Sessions carried by a cookie. Sessions: per-visitor state carried by a cookie.
A SessionStore trait plus a cookie-backed
implementation. The session is a string map, seeded into the call by
Sessions and read with the Session extractor.
use churust_core::{Call, Churust, Session, Sessions, TestClient};
let app = Churust::server()
.install(Sessions::cookie("change-me-in-production"))
.routing(|r| {
r.get("/visit", |s: Session| async move {
let n: u32 = s.get("count").and_then(|v| v.parse().ok()).unwrap_or(0);
s.set("count", (n + 1).to_string());
format!("visit {}", n + 1)
});
})
.build();
let res = TestClient::new(app).get("/visit").send().await;
assert_eq!(res.text(), "visit 1");
assert!(res.header("set-cookie").is_some());Structs§
- Cookie
Store - Keeps the whole session in the cookie, signed with HMAC-SHA256 so a client cannot edit it.
- Session
- A handle to the current visitor’s session.
- Sessions
- Installs session handling. See the module docs.
Constants§
- SESSION_
ID_ KEY - The reserved key under which a server-side
SessionStorerecords which row, document or Redis key this session is.
Traits§
- Session
Store - Where session contents live between requests.