A Cookie library for parsing and managing HTTP Cookies.
jiff, adds support for the jiff crate.chrono, adds support for the chrono crate.time, adds support for the time crate.percent-encode, percent-encode/decode cookies.axum, adds integration with the axum crate.http, adds integration with the http crate.
# Cargo.toml
[dependencies]
cookie-monster = "0.1"
# Integration with the `time` crate
cookie-monster = { version = "0.1", features = ["time"] }
# Integration with the`chrono` crate
cookie-monster = { version = "0.1", features = ["chrono"] }
# Integration with the `jiff` crate
cookie-monster = { version = "0.1", features = ["jiff"] }
# Adds support for percent-encoding/decoding cookies.
cookie-monster = { version = "0.1", features = ["percent-encoding"] }
# Integration with the `axum` crate.
cookie-monster = { version = "0.1", features = ["axum"] }
# Integration with the `http` crate.
cookie-monster = { version = "0.1", features = ["http"] }use axum::response::IntoResponse;
use cookie_monster::{Cookie, CookieJar, SameSite};
static COOKIE_NAME: &str = "session";
async fn handler(mut jar: CookieJar) -> impl IntoResponse {
if let Some(cookie) = jar.get(COOKIE_NAME) {
// Remove cookie
println!("Removing cookie {cookie:?}");
jar.remove(Cookie::named(COOKIE_NAME));
} else {
// Set cookie.
let cookie = Cookie::build(COOKIE_NAME, "hello, world")
.http_only()
.same_site(SameSite::Strict);
println!("Setting cookie {cookie:?}");
jar.add(cookie);
}
// Return the jar so the cookies are updated
jar
}The cookie-monster crate has rust version 1.85 as MSRV.
This crate takes a lot of inspiration from the cookie crate.
This project is licensed under the MIT license.