#[request_cookies]Expand description
Extracts all cookies as a raw string into a variable.
This attribute macro retrieves the entire Cookie header from the request and makes it available as a String variable. If no Cookie header is present, an empty string is used.
§Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/cookies")]
struct Cookies;
impl ServerHook for Cookies {
async fn new(_ctx: &mut Context) -> Self {
Self
}
#[response_body(&format!("All cookies: {cookie_value:?}"))]
#[request_cookies(cookie_value)]
async fn handle(self, ctx: &mut Context) {}
}
impl Cookies {
#[request_cookies(cookie_value)]
async fn request_cookies_with_ref_self(&self, ctx: &mut Context) {}
}
#[request_cookies(cookie_value)]
async fn standalone_request_cookies_handler(ctx: &mut Context) {}The macro accepts a variable name that will contain all cookies. The variable will be available as a Cookies type in the function scope.
§Multi-Parameter Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/multi_cookies")]
struct MultiCookies;
impl ServerHook for MultiCookies {
async fn new(_ctx: &mut Context) -> Self {
Self
}
#[response_body(&format!("cookies1: {cookies1:?}, cookies2: {cookies2:?}"))]
#[request_cookies(cookies1, cookies2)]
async fn handle(self, ctx: &mut Context) {}
}