Skip to main content

unknown_method

Attribute Macro unknown_method 

Source
#[unknown_method]
Expand description

Restricts function execution to unknown HTTP methods only.

This attribute macro ensures the decorated function only executes when the incoming request uses an HTTP method that is not one of the standard methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT, TRACE). Requests with standard methods will be filtered out.

ยงUsage

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

#[route("/unknown_method")]
struct UnknownMethod;

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

    #[prologue_macros(
        clear_response_headers,
        filter(ctx.get_request().get_method().is_unknown()),
        response_body("unknown_method")
    )]
    async fn handle(self, stream: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
}

impl UnknownMethod {
    #[unknown_method]
    async fn unknown_method_with_ref_self(&self, stream: &mut Stream, ctx: &mut Context) -> Status { Status::Continue }
}

#[unknown_method]
async fn standalone_unknown_method_handler(stream: &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.