[−][src]Module roa::cookie
The cookie module of roa.
This module provides a middleware cookie_parser
and a context extension Cookier
.
Example
use roa::cookie::{cookie_parser, Cookier}; use roa::core::{App, StatusCode}; use roa::core::header::COOKIE; use async_std::task::spawn; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let (addr, server) = App::new(()) .gate(cookie_parser) .end(|ctx| async move { assert_eq!("Hexilee", ctx.must_cookie("name").await?); Ok(()) }) .run_local()?; spawn(server); let client = reqwest::Client::new(); let resp = client .get(&format!("http://{}", addr)) .header(COOKIE, "name=Hexilee") .send() .await?; assert_eq!(StatusCode::OK, resp.status()); Ok(()) }
Structs
Cookie | Representation of an HTTP cookie. |
Traits
Cookier | A context extension.
The |
Functions
cookie_parser | A middleware to parse cookie. |