request_header

Attribute Macro request_header 

Source
#[request_header]
Expand description

Extracts a specific HTTP request header into a variable.

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.

ยง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_option),
        response_body(&format!("request header: {request_header_option:?}")),
        send
    )]
    async fn handle(self, 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<String>.