#[response_header]Expand description
Sets or replaces 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.
Use "key", "value" to set a header (add to existing headers) or "key" => "value" to replace a header (overwrite existing).
ยงUsage
use hyperlane::*;
use hyperlane_macros::*;
const CUSTOM_HEADER_NAME: &str = "X-Custom-Header";
const CUSTOM_HEADER_VALUE: &str = "custom-value";
#[route("/response")]
struct Response;
impl ServerHook for Response {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_header(CUSTOM_HEADER_NAME => CUSTOM_HEADER_VALUE)]
async fn handle(self, ctx: &Context) {}
}
#[route("/response_header")]
struct ResponseHeaderTest;
impl ServerHook for ResponseHeaderTest {
async fn new(_ctx: &Context) -> Self {
Self
}
#[response_body("Testing header set and replace operations")]
#[response_header("X-Add-Header", "add-value")]
#[response_header("X-Set-Header" => "set-value")]
async fn handle(self, ctx: &Context) {}
}The macro accepts header name and header value, both can be string literals or global constants.
Use "key", "value" for setting headers and "key" => "value" for replacing headers.
Should be applied to async functions that accept a &Context parameter.