#[header]
Expand description
Extracts a specific HTTP header into a variable.
This attribute macro retrieves a specific HTTP header by name and makes it available as a variable. Header values are extracted from the request headers collection.
ยงUsage
use hyperlane_macros::*;
use hyperlane::*;
#[header(HOST => host_header)]
async fn handle_with_host(ctx: Context) {
if let Some(host) = host_header {
// Use the host header value
}
}
#[header("Content-Type" => content_type)]
async fn handle_with_content_type(ctx: Context) {
if let Some(ct) = content_type {
// Use the content type header
}
}
The macro accepts a 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<String>
.