Skip to main content

is_options_method

Attribute Macro is_options_method 

Source
#[is_options_method]
Expand description

Restricts function execution to HTTP OPTIONS requests only.

This attribute macro ensures the decorated function only executes when the incoming request uses the OPTIONS HTTP method. Requests with other methods will be filtered out.

ยงUsage

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

#[route("/is_options_method")]
struct Options;

impl ServerHook for Options {
    async fn new(_: &mut Stream, _: &mut Context) -> Self {
        Self
    }

    #[prologue_macros(is_options_method, response_body("is_options_method"))]
    async fn handle(self, _: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
}

impl Options {
    #[is_options_method]
    async fn options_with_ref_self(&self, _: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
}

#[is_options_method]
async fn standalone_options_handler(_: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }

The macro takes no parameters and should be applied directly to async functions that accept a &mut Context parameter.