#[request_header]Expand description
Extracts a specific HTTP request header into a variable with panic on missing value.
This attribute macro retrieves a specific HTTP request header by name and makes it available as a variable. Header values are extracted from the request request headers collection. If the requested header does not exist, the function will panic with an error message.
§Usage
use hyperlane::*;
use hyperlane_macros::*;
#[route("/request_header")]
struct RequestHeader;
impl ServerHook for RequestHeader {
async fn new(_ctx: &Context) -> Self {
Self
}
#[prologue_macros(
request_header(HOST => request_header),
response_body(&format!("request header: {request_header}")),
send
)]
async fn handle(self, ctx: &Context) {}
}
impl RequestHeader {
#[request_header(HOST => request_header)]
async fn request_header_with_ref_self(&self, ctx: &Context) {}
}
#[request_header(HOST => request_header)]
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 RequestHeadersValueItem.
§Panics
This macro will panic if the requested header does not exist in the HTTP request headers.