[][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 cookie and must_cookie method of this extension must be used in downstream of middleware cookier_parser, otherwise you cannot get expected cookie.

Functions

cookie_parser

A middleware to parse cookie.