Axum Cookie Middleware
This library provides a middleware layer for integrating cookie management into Axum applications.
It allows parsing cookies from incoming requests, managing cookies
and setting Set-Cookie headers in HTTP responses.
Features
- Middleware integration with Axum.
- Flexible cookie parsing (strict or lenient mode).
- Thread-safe cookie management.
- Automatic handling of
Set-Cookieheaders.
Usage
Add the library to your Cargo.toml:
[dependencies]
...
+ axum-cookie = "0.2.4"
Example: Basic Integration
use ;
use *;
async
let app: = new
.route
.layer;
Example: Strict Cookie Parsing
use ;
use CookieLayer;
let app: = new
.route
.layer;
API
CookieManager
CookieManager::new- Creates a new cookie manager with a specifiedCookieJar.CookieManager::add- Adds a cookie to the jar.CookieManager::remove- Removes a cookie by its name.CookieManager::get- Retrieves a cookie by its name.CookieManager::cookie- Returns all cookies in the jar.CookieManager::as_header_value- GeneratesSet-Cookieheader value for all cookies in the jar.
CookieLayer
CookieLayer::default- Creates a layer with lenient cookie parsing.CookieLayer::strict- Creates a layer with strict cookie parsing.
CookieMiddleware
- Handles parsing cookies from requests.
- Adds
Set-Cookieheaders to responses.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.