Attribute Macro response_header

Source
#[response_header]
Expand description

Sets a specific HTTP response header.

This attribute macro configures a specific HTTP response header that will be sent with the response. Both the header name and value can be provided as string literals or global constants.

ยงUsage

use hyperlane::*;
use hyperlane_macros::*;

const HEADER_NAME: &str = "X-Custom-Header";
const HEADER_VALUE: &str = "custom-value";

#[response_header("Content-Type" => "application/json")]
async fn json_handler(ctx: Context) {
    // Response will have Content-Type header set to application/json
}

#[response_header("X-Static-Header" => "static-value")]
async fn static_header_handler(ctx: Context) {
    // Response will have static header
}

#[response_header(HEADER_NAME => HEADER_VALUE)]
async fn dynamic_header_handler(ctx: Context) {
    // Response will have header from global constants
}

The macro accepts two parameters: header name and header value, both can be string literals or global constants. Should be applied to async functions that accept a Context parameter.