#[request_cookie]Expand description
Extracts a specific cookie value or all cookies into a variable.
This attribute macro supports two syntaxes:
cookie(key => variable_name)- Extract a specific cookie value by keycookie(variable_name)- Extract all cookies as a raw string
ยงUsage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/cookie")]
struct Cookie;
impl ServerHook for Cookie {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body(&format!("Session cookie: {session_cookie_opt:?}"))]
#[request_cookie("test" => session_cookie_opt)]
async fn handle(self, ctx: &Context) {}
}For specific cookie extraction, the variable will be available as Option<String>.
For all cookies extraction, the variable will be available as String.