#axum #cookie #cookies #tower

tower-cookies

Cookie manager middleware for tower

14 releases (8 breaking)

0.9.0 Feb 12, 2023
0.8.0 Nov 25, 2022
0.7.0 Jun 9, 2022
0.5.1 Feb 23, 2022
0.3.0 Nov 18, 2021

#178 in Web programming

Download history 1925/week @ 2023-05-31 1810/week @ 2023-06-07 1564/week @ 2023-06-14 1769/week @ 2023-06-21 1558/week @ 2023-06-28 2106/week @ 2023-07-05 1552/week @ 2023-07-12 1534/week @ 2023-07-19 1618/week @ 2023-07-26 1541/week @ 2023-08-02 1597/week @ 2023-08-09 1740/week @ 2023-08-16 1888/week @ 2023-08-23 1924/week @ 2023-08-30 1942/week @ 2023-09-06 1534/week @ 2023-09-13

7,595 downloads per month
Used in 11 crates (9 directly)

MIT license

25KB
458 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));
    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

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.7–8.5MB
~73K SLoC