host

Attribute Macro host 

Source
#[host]
Expand description

Restricts function execution to requests with a specific host.

This attribute macro ensures the decorated function only executes when the incoming request has a host header that matches the specified value. Requests with different or missing host headers will be filtered out.

ยงUsage

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

#[route("/host")]
struct Host;

impl ServerHook for Host {
    async fn new(_ctx: &Context) -> Self {
        Self
    }

    #[host("localhost")]
    #[prologue_macros(response_body("host string literal: localhost"), send)]
    async fn handle(self, ctx: &Context) {}
}

impl Host {
    #[host("localhost")]
    async fn host_with_ref_self(&self, ctx: &Context) {}
}

#[host("localhost")]
async fn standalone_host_handler(ctx: &Context) {}

The macro accepts a string literal specifying the expected host value and should be applied to async functions that accept a &Context parameter.