#[request_header_option]Expand description
Extracts a specific HTTP request header into a variable wrapped in Option type.
This attribute macro retrieves a specific HTTP request header by name and makes it available as an Option variable. Header values are extracted from the request request headers collection and wrapped in an Option type to safely handle cases where the header may not exist.
ยงUsage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_header_option")]
struct RequestHeader;
impl ServerHook for RequestHeader {
async fn new(_ctx: &Context) -> Self {
Self
}
#[prologue_macros(
request_header_option(HOST => request_header_option),
response_body(&format!("request header: {request_header_option:?}")),
send
)]
async fn handle(self, ctx: &Context) {}
}
impl RequestHeader {
#[request_header_option(HOST => request_header_option)]
async fn request_header_with_ref_self(&self, ctx: &Context) {}
}
#[request_header_option(HOST => request_header_option)]
async fn standalone_request_header_handler(ctx: &Context) {}The macro accepts a request header name-to-variable mapping in the format HEADER_NAME => variable_name
or "Header-Name" => variable_name. The variable will be available as an Option<RequestHeadersValueItem>.