#axum #cookie #cookies #tower

tower-cookies

Cookie manager middleware for tower

8 unstable releases (3 breaking)

Uses new Rust 2021

0.4.1 Jan 3, 2022
0.4.0 Dec 3, 2021
0.3.0 Nov 18, 2021
0.2.2 Nov 18, 2021
0.1.1 Oct 15, 2021

#117 in Web programming

Download history 43/week @ 2021-10-11 13/week @ 2021-10-18 18/week @ 2021-10-25 67/week @ 2021-11-01 48/week @ 2021-11-08 76/week @ 2021-11-15 144/week @ 2021-11-22 183/week @ 2021-11-29 194/week @ 2021-12-06 136/week @ 2021-12-13 204/week @ 2021-12-20 107/week @ 2021-12-27 231/week @ 2022-01-03 135/week @ 2022-01-10 151/week @ 2022-01-17

634 downloads per month
Used in 6 crates (5 directly)

MIT license

24KB
471 lines

License Crates.io Documentation

tower-cookies

A cookie manager middleware built on top of tower.

Example

With axum:

use axum::{routing::get, Router};
use std::net::SocketAddr;
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/", get(handler))
        .layer(CookieManagerLayer::new());

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

async fn handler(cookies: Cookies) -> &'static str {
    cookies.add(Cookie::new("hello_world", "hello_world"));

    "Check your cookies."
}

A complete CRUD cookie example in examples/counter.rs

Safety

This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

Contributing

We appreciate all kinds of contributions, thank you!

Note on README

The README.md file isn't meant to be changed directly. It instead generated from the crate's docs by the cargo-readme command:

  • Install the command if you don't have it: cargo install cargo-readme
  • Change the crate-level docs in src/lib.rs, or wrapping text in README.tpl
  • Apply the changes: cargo readme > README.md

If you have rusty-hook installed the changes will apply automatically on commit.

License

This project is licensed under the MIT license.

Dependencies

~2–3MB
~61K SLoC