#cookies #axum #tower

tower-cookies

Cookie manager middleware for tower

15 releases (9 breaking)

0.10.0 Nov 27, 2023
0.9.0 Feb 12, 2023
0.8.0 Nov 25, 2022
0.7.0 Jun 9, 2022
0.3.0 Nov 18, 2021

#3 in #cookies

Download history 5141/week @ 2024-01-25 5623/week @ 2024-02-01 6959/week @ 2024-02-08 5236/week @ 2024-02-15 5977/week @ 2024-02-22 7615/week @ 2024-02-29 7452/week @ 2024-03-07 6808/week @ 2024-03-14 8258/week @ 2024-03-21 7405/week @ 2024-03-28 8051/week @ 2024-04-04 7885/week @ 2024-04-11 6983/week @ 2024-04-18 7723/week @ 2024-04-25 6588/week @ 2024-05-02 5371/week @ 2024-05-09

27,944 downloads per month
Used in 42 crates (17 directly)

MIT license

26KB
455 lines

License Crates.io Docs.rs

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));
    let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
    axum::serve(listener, 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

Most of the readme is automatically copied from the crate documentation by cargo-sync-readme. This way the readme is always in sync with the docs and examples are tested.

So if you find a part of the readme you'd like to change between <!-- cargo-sync-readme start --> and <!-- cargo-sync-readme end --> markers, don't edit README.md directly, but rather change the documentation on top of src/lib.rs and then synchronize the readme with:

cargo sync-readme

(make sure the cargo command is installed):

cargo install cargo-sync-readme

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

License

This project is licensed under the MIT license.

Dependencies

~2.9–9.5MB
~78K SLoC