Skip to main content

hyperlane_macros/
lib.rs

1//! hyperlane-macros
2//!
3//! A comprehensive collection of procedural macros for building
4//! HTTP servers with enhanced functionality. This crate provides
5//! attribute macros that simplify HTTP request handling, protocol
6//! validation, response management, and request data extraction.
7
8mod aborted;
9mod closed;
10mod common;
11mod filter;
12mod flush;
13mod from_stream;
14mod hook;
15mod host;
16mod hyperlane;
17mod inject;
18mod method;
19mod referer;
20mod reject;
21mod request;
22mod request_middleware;
23mod response;
24mod response_middleware;
25mod route;
26mod send;
27mod stream;
28mod upgrade;
29mod version;
30
31use {
32    aborted::*, closed::*, common::*, filter::*, flush::*, from_stream::*, hook::*, host::*,
33    hyperlane::*, inject::*, method::*, referer::*, reject::*, request::*, request_middleware::*,
34    response::*, response_middleware::*, route::*, send::*, stream::*, upgrade::*, version::*,
35};
36
37use {
38    ::hyperlane::inventory,
39    proc_macro::TokenStream,
40    proc_macro2::TokenStream as TokenStream2,
41    quote::quote,
42    syn::{
43        Ident, Token,
44        parse::{Parse, ParseStream, Parser, Result},
45        punctuated::Punctuated,
46        token::Comma,
47        *,
48    },
49};
50
51inventory::collect!(InjectableMacro);
52
53/// Wraps function body with WebSocket stream processing.
54///
55/// This attribute macro generates code that wraps the function body with a check to see if
56/// data can be read from a WebSocket stream. The function body is only executed
57/// if data is successfully read from the stream.
58///
59/// This attribute macro generates code that wraps the function body with a check to see if
60/// data can be read from a WebSocket stream. The function body is only executed
61/// if data is successfully read from the stream.
62///
63/// # Arguments
64///
65/// - `TokenStream`: The buffer to read from the WebSocket stream.
66/// - `TokenStream`: The function item to be modified
67///
68/// # Returns
69///
70/// Returns a TokenStream containing the modified function with WebSocket stream processing logic.
71///
72/// # Examples
73///
74/// Using no parameters (default buffer size):
75///
76/// ```rust
77/// use hyperlane::*;
78/// use hyperlane_macros::*;
79///
80/// #[route("/ws_upgrade_type")]
81/// struct Websocket;
82///
83/// impl ServerHook for Websocket {
84///     async fn new(_ctx: &Context) -> Self {
85///         Self
86///     }
87///
88///     #[ws_upgrade_type]
89///     #[ws_from_stream]
90///     async fn handle(self, ctx: &Context) {
91///         let body: RequestBody = ctx.get_request_body().await;
92///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
93///         ctx.send_body_list_with_data(&body_list).await;
94///     }
95/// }
96/// ```
97///
98/// Using only request config:
99///
100/// ```rust
101/// use hyperlane::*;
102/// use hyperlane_macros::*;
103///
104/// #[route("/ws_upgrade_type")]
105/// struct Websocket;
106///
107/// impl ServerHook for Websocket {
108///     async fn new(_ctx: &Context) -> Self {
109///         Self
110///     }
111///
112///     #[ws_upgrade_type]
113///     #[ws_from_stream(&RequestConfigData::default())]
114///     async fn handle(self, ctx: &Context) {
115///         let body: RequestBody = ctx.get_request_body().await;
116///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
117///         ctx.send_body_list_with_data(&body_list).await;
118///     }
119/// }
120/// ```
121///
122/// Using variable name to store request data:
123///
124/// ```rust
125/// use hyperlane::*;
126/// use hyperlane_macros::*;
127///
128/// #[route("/ws_upgrade_type")]
129/// struct Websocket;
130///
131/// impl ServerHook for Websocket {
132///     async fn new(_ctx: &Context) -> Self {
133///         Self
134///     }
135///
136///     #[ws_upgrade_type]
137///     #[ws_from_stream(request)]
138///     async fn handle(self, ctx: &Context) {
139///         let body: &RequestBody = &request.get_body();
140///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(body);
141///         ctx.send_body_list_with_data(&body_list).await;
142///     }
143/// }
144/// ```
145///
146/// Using request config and variable name:
147///
148/// ```rust
149/// use hyperlane::*;
150/// use hyperlane_macros::*;
151///
152/// #[route("/ws_upgrade_type")]
153/// struct Websocket;
154///
155/// impl ServerHook for Websocket {
156///     async fn new(_ctx: &Context) -> Self {
157///         Self
158///     }
159///
160///     #[ws_upgrade_type]
161///     #[ws_from_stream(&RequestConfigData::default(), request)]
162///     async fn handle(self, ctx: &Context) {
163///         let body: &RequestBody = request.get_body();
164///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
165///         ctx.send_body_list_with_data(&body_list).await;
166///     }
167/// }
168/// ```
169///
170/// Using variable name and request config (reversed order):
171///
172/// ```rust
173/// use hyperlane::*;
174/// use hyperlane_macros::*;
175///
176/// #[route("/ws_upgrade_type")]
177/// struct Websocket;
178///
179/// impl ServerHook for Websocket {
180///     async fn new(_ctx: &Context) -> Self {
181///         Self
182///     }
183///
184///     #[ws_upgrade_type]
185///     #[ws_from_stream(request, &RequestConfigData::default())]
186///     async fn handle(self, ctx: &Context) {
187///         let body: &RequestBody = request.get_body();
188///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
189///         ctx.send_body_list_with_data(&body_list).await;
190///     }
191/// }
192///
193/// impl Websocket {
194///     #[ws_from_stream(request)]
195///     async fn ws_from_stream_with_ref_self(&self, ctx: &Context) {}
196/// }
197///
198/// #[ws_from_stream]
199/// async fn standalone_ws_from_stream_handler(ctx: &Context) {}
200/// ```
201#[proc_macro_attribute]
202pub fn ws_from_stream(attr: TokenStream, item: TokenStream) -> TokenStream {
203    ws_from_stream_macro(attr, item)
204}
205
206/// Wraps function body with HTTP stream processing.
207///
208/// This attribute macro generates code that wraps the function body with a check to see if
209/// data can be read from an HTTP stream. The function body is only executed
210/// if data is successfully read from the stream.
211///
212/// This attribute macro generates code that wraps the function body with a check to see if
213/// data can be read from an HTTP stream. The function body is only executed
214/// if data is successfully read from the stream.
215///
216/// # Arguments
217///
218/// - `TokenStream`: The buffer to read from the HTTP stream.
219/// - `TokenStream`: The function item to be modified
220///
221/// # Returns
222///
223/// Returns a TokenStream containing the modified function with HTTP stream processing logic.
224///
225/// # Examples
226///
227/// Using with epilogue_macros:
228///
229/// ```rust
230/// use hyperlane::*;
231/// use hyperlane_macros::*;
232///
233/// #[route("/http_from_stream")]
234/// struct HttpFromStreamTest;
235///
236/// impl ServerHook for HttpFromStreamTest {
237///     async fn new(_ctx: &Context) -> Self {
238///         Self
239///     }
240///
241///     #[epilogue_macros(
242///         request_query("test" => request_query_option),
243///         response_body(&format!("request query: {request_query_option:?}")),
244///         send,
245///         http_from_stream(&RequestConfigData::default())
246///     )]
247///     async fn handle(self, ctx: &Context) {}
248/// }
249/// ```
250///
251/// Using with variable name:
252///
253/// ```rust
254/// use hyperlane::*;
255/// use hyperlane_macros::*;
256///
257/// #[route("/http_from_stream")]
258/// struct HttpFromStreamTest;
259///
260/// impl ServerHook for HttpFromStreamTest {
261///     async fn new(_ctx: &Context) -> Self {
262///         Self
263///     }
264///
265///     #[epilogue_macros(
266///         http_from_stream(_request)
267///     )]
268///     async fn handle(self, ctx: &Context) {}
269/// }
270///
271/// impl HttpFromStreamTest {
272///     #[http_from_stream(_request)]
273///     async fn http_from_stream_with_ref_self(&self, ctx: &Context) {}
274/// }
275///
276/// #[http_from_stream]
277/// async fn standalone_http_from_stream_handler(ctx: &Context) {}
278/// ```
279#[proc_macro_attribute]
280pub fn http_from_stream(attr: TokenStream, item: TokenStream) -> TokenStream {
281    http_from_stream_macro(attr, item)
282}
283
284/// Restricts function execution to HTTP GET requests only.
285///
286/// This attribute macro ensures the decorated function only executes when the incoming request
287/// uses the GET HTTP method. Requests with other methods will be filtered out.
288///
289/// # Usage
290///
291/// ```rust
292/// use hyperlane::*;
293/// use hyperlane_macros::*;
294///
295/// #[route("/get_method")]
296/// struct Get;
297///
298/// impl ServerHook for Get {
299///     async fn new(_ctx: &Context) -> Self {
300///         Self
301///     }
302///
303///     #[prologue_macros(get_method, response_body("get_method"))]
304///     async fn handle(self, ctx: &Context) {}
305/// }
306///
307/// impl Get {
308///     #[get_method]
309///     async fn get_with_ref_self(&self, ctx: &Context) {}
310/// }
311///
312/// #[get_method]
313/// async fn standalone_get_handler(ctx: &Context) {}
314/// ```
315///
316/// The macro takes no parameters and should be applied directly to async functions
317/// that accept a `&Context` parameter.
318#[proc_macro_attribute]
319pub fn get_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
320    get_method_handler(item, Position::Prologue)
321}
322
323/// Restricts function execution to HTTP POST requests only.
324///
325/// This attribute macro ensures the decorated function only executes when the incoming request
326/// uses the POST HTTP method. Requests with other methods will be filtered out.
327///
328/// # Usage
329///
330/// ```rust
331/// use hyperlane::*;
332/// use hyperlane_macros::*;
333///
334/// #[route("/post_method")]
335/// struct Post;
336///
337/// impl ServerHook for Post {
338///     async fn new(_ctx: &Context) -> Self {
339///         Self
340///     }
341///
342///     #[prologue_macros(post_method, response_body("post_method"))]
343///     async fn handle(self, ctx: &Context) {}
344/// }
345///
346/// impl Post {
347///     #[post_method]
348///     async fn post_with_ref_self(&self, ctx: &Context) {}
349/// }
350///
351/// #[post_method]
352/// async fn standalone_post_handler(ctx: &Context) {}
353/// ```
354///
355/// The macro takes no parameters and should be applied directly to async functions
356/// that accept a `&Context` parameter.
357#[proc_macro_attribute]
358pub fn post_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
359    post_method_handler(item, Position::Prologue)
360}
361
362/// Restricts function execution to HTTP PUT requests only.
363///
364/// This attribute macro ensures the decorated function only executes when the incoming request
365/// uses the PUT HTTP method. Requests with other methods will be filtered out.
366///
367/// # Usage
368///
369/// ```rust
370/// use hyperlane::*;
371/// use hyperlane_macros::*;
372///
373/// #[route("/put_method")]
374/// struct Put;
375///
376/// impl ServerHook for Put {
377///     async fn new(_ctx: &Context) -> Self {
378///         Self
379///     }
380///
381///     #[prologue_macros(put_method, response_body("put_method"))]
382///     async fn handle(self, ctx: &Context) {}
383/// }
384///
385/// impl Put {
386///     #[put_method]
387///     async fn put_with_ref_self(&self, ctx: &Context) {}
388/// }
389///
390/// #[put_method]
391/// async fn standalone_put_handler(ctx: &Context) {}
392/// ```
393///
394/// The macro takes no parameters and should be applied directly to async functions
395/// that accept a `&Context` parameter.
396#[proc_macro_attribute]
397pub fn put_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
398    put_method_handler(item, Position::Prologue)
399}
400
401/// Restricts function execution to HTTP DELETE requests only.
402///
403/// This attribute macro ensures the decorated function only executes when the incoming request
404/// uses the DELETE HTTP method. Requests with other methods will be filtered out.
405///
406/// # Usage
407///
408/// ```rust
409/// use hyperlane::*;
410/// use hyperlane_macros::*;
411///
412/// #[route("/delete_method")]
413/// struct Delete;
414///
415/// impl ServerHook for Delete {
416///     async fn new(_ctx: &Context) -> Self {
417///         Self
418///     }
419///
420///     #[prologue_macros(delete_method, response_body("delete_method"))]
421///     async fn handle(self, ctx: &Context) {}
422/// }
423///
424/// impl Delete {
425///     #[delete_method]
426///     async fn delete_with_ref_self(&self, ctx: &Context) {}
427/// }
428///
429/// #[delete_method]
430/// async fn standalone_delete_handler(ctx: &Context) {}
431/// ```
432///
433/// The macro takes no parameters and should be applied directly to async functions
434/// that accept a `&Context` parameter.
435#[proc_macro_attribute]
436pub fn delete_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
437    delete_method_handler(item, Position::Prologue)
438}
439
440/// Restricts function execution to HTTP PATCH requests only.
441///
442/// This attribute macro ensures the decorated function only executes when the incoming request
443/// uses the PATCH HTTP method. Requests with other methods will be filtered out.
444///
445/// # Usage
446///
447/// ```rust
448/// use hyperlane::*;
449/// use hyperlane_macros::*;
450///
451/// #[route("/patch_method")]
452/// struct Patch;
453///
454/// impl ServerHook for Patch {
455///     async fn new(_ctx: &Context) -> Self {
456///         Self
457///     }
458///
459///     #[prologue_macros(patch_method, response_body("patch_method"))]
460///     async fn handle(self, ctx: &Context) {}
461/// }
462///
463/// impl Patch {
464///     #[patch_method]
465///     async fn patch_with_ref_self(&self, ctx: &Context) {}
466/// }
467///
468/// #[patch_method]
469/// async fn standalone_patch_handler(ctx: &Context) {}
470/// ```
471///
472/// The macro takes no parameters and should be applied directly to async functions
473/// that accept a `&Context` parameter.
474#[proc_macro_attribute]
475pub fn patch_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
476    patch_method_handler(item, Position::Prologue)
477}
478
479/// Restricts function execution to HTTP HEAD requests only.
480///
481/// This attribute macro ensures the decorated function only executes when the incoming request
482/// uses the HEAD HTTP method. Requests with other methods will be filtered out.
483///
484/// # Usage
485///
486/// ```rust
487/// use hyperlane::*;
488/// use hyperlane_macros::*;
489///
490/// #[route("/head_method")]
491/// struct Head;
492///
493/// impl ServerHook for Head {
494///     async fn new(_ctx: &Context) -> Self {
495///         Self
496///     }
497///
498///     #[prologue_macros(head_method, response_body("head_method"))]
499///     async fn handle(self, ctx: &Context) {}
500/// }
501///
502/// impl Head {
503///     #[head_method]
504///     async fn head_with_ref_self(&self, ctx: &Context) {}
505/// }
506///
507/// #[head_method]
508/// async fn standalone_head_handler(ctx: &Context) {}
509/// ```
510///
511/// The macro takes no parameters and should be applied directly to async functions
512/// that accept a `&Context` parameter.
513#[proc_macro_attribute]
514pub fn head_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
515    head_method_handler(item, Position::Prologue)
516}
517
518/// Restricts function execution to HTTP OPTIONS requests only.
519///
520/// This attribute macro ensures the decorated function only executes when the incoming request
521/// uses the OPTIONS HTTP method. Requests with other methods will be filtered out.
522///
523/// # Usage
524///
525/// ```rust
526/// use hyperlane::*;
527/// use hyperlane_macros::*;
528///
529/// #[route("/options_method")]
530/// struct Options;
531///
532/// impl ServerHook for Options {
533///     async fn new(_ctx: &Context) -> Self {
534///         Self
535///     }
536///
537///     #[prologue_macros(options_method, response_body("options_method"))]
538///     async fn handle(self, ctx: &Context) {}
539/// }
540///
541/// impl Options {
542///     #[options_method]
543///     async fn options_with_ref_self(&self, ctx: &Context) {}
544/// }
545///
546/// #[options_method]
547/// async fn standalone_options_handler(ctx: &Context) {}
548/// ```
549///
550/// The macro takes no parameters and should be applied directly to async functions
551/// that accept a `&Context` parameter.
552#[proc_macro_attribute]
553pub fn options_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
554    options_method_handler(item, Position::Prologue)
555}
556
557/// Restricts function execution to HTTP CONNECT requests only.
558///
559/// This attribute macro ensures the decorated function only executes when the incoming request
560/// uses the CONNECT HTTP method. Requests with other methods will be filtered out.
561///
562/// # Usage
563///
564/// ```rust
565/// use hyperlane::*;
566/// use hyperlane_macros::*;
567///
568/// #[route("/connect_method")]
569/// struct Connect;
570///
571/// impl ServerHook for Connect {
572///     async fn new(_ctx: &Context) -> Self {
573///         Self
574///     }
575///
576///     #[prologue_macros(connect_method, response_body("connect_method"))]
577///     async fn handle(self, ctx: &Context) {}
578/// }
579///
580/// impl Connect {
581///     #[connect_method]
582///     async fn connect_with_ref_self(&self, ctx: &Context) {}
583/// }
584///
585/// #[connect_method]
586/// async fn standalone_connect_handler(ctx: &Context) {}
587/// ```
588///
589/// The macro takes no parameters and should be applied directly to async functions
590/// that accept a `&Context` parameter.
591#[proc_macro_attribute]
592pub fn connect_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
593    connect_method_handler(item, Position::Prologue)
594}
595
596/// Restricts function execution to HTTP TRACE requests only.
597///
598/// This attribute macro ensures the decorated function only executes when the incoming request
599/// uses the TRACE HTTP method. Requests with other methods will be filtered out.
600///
601/// # Usage
602///
603/// ```rust
604/// use hyperlane::*;
605/// use hyperlane_macros::*;
606///
607/// #[route("/trace_method")]
608/// struct Trace;
609///
610/// impl ServerHook for Trace {
611///     async fn new(_ctx: &Context) -> Self {
612///         Self
613///     }
614///
615///     #[prologue_macros(trace_method, response_body("trace_method"))]
616///     async fn handle(self, ctx: &Context) {}
617/// }
618///
619/// impl Trace {
620///     #[trace_method]
621///     async fn trace_with_ref_self(&self, ctx: &Context) {}
622/// }
623///
624/// #[trace_method]
625/// async fn standalone_trace_handler(ctx: &Context) {}
626/// ```
627///
628/// The macro takes no parameters and should be applied directly to async functions
629/// that accept a `&Context` parameter.
630#[proc_macro_attribute]
631pub fn trace_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
632    trace_method_handler(item, Position::Prologue)
633}
634
635/// Restricts function execution to unknown HTTP methods only.
636///
637/// This attribute macro ensures the decorated function only executes when the incoming request
638/// uses an HTTP method that is not one of the standard methods (GET, POST, PUT, DELETE, PATCH,
639/// HEAD, OPTIONS, CONNECT, TRACE). Requests with standard methods will be filtered out.
640///
641/// # Usage
642///
643/// ```rust
644/// use hyperlane::*;
645/// use hyperlane_macros::*;
646///
647/// #[route("/unknown_method")]
648/// struct UnknownMethod;
649///
650/// impl ServerHook for UnknownMethod {
651///     async fn new(_ctx: &Context) -> Self {
652///         Self
653///     }
654///
655///     #[prologue_macros(
656///         clear_response_headers,
657///         filter(ctx.get_request_is_unknown_method().await),
658///         response_body("unknown_method")
659///     )]
660///     async fn handle(self, ctx: &Context) {}
661/// }
662///
663/// impl UnknownMethod {
664///     #[unknown_method]
665///     async fn unknown_method_with_ref_self(&self, ctx: &Context) {}
666/// }
667///
668/// #[unknown_method]
669/// async fn standalone_unknown_method_handler(ctx: &Context) {}
670/// ```
671///
672/// The macro takes no parameters and should be applied directly to async functions
673/// that accept a `&Context` parameter.
674#[proc_macro_attribute]
675pub fn unknown_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
676    unknown_method_handler(item, Position::Prologue)
677}
678
679/// Allows function to handle multiple HTTP methods.
680///
681/// This attribute macro configures the decorated function to execute for any of the specified
682/// HTTP methods. Methods should be provided as a comma-separated list.
683///
684/// # Usage
685///
686/// ```rust
687/// use hyperlane::*;
688/// use hyperlane_macros::*;
689///
690/// #[route("/methods")]
691/// struct GetPost;
692///
693/// impl ServerHook for GetPost {
694///     async fn new(_ctx: &Context) -> Self {
695///         Self
696///     }
697///
698///     #[prologue_macros(
699///         http_version,
700///         methods(get, post),
701///         response_body("methods")
702///     )]
703///     async fn handle(self, ctx: &Context) {}
704/// }
705///
706/// impl GetPost {
707///     #[methods(get, post)]
708///     async fn methods_with_ref_self(&self, ctx: &Context) {}
709/// }
710///
711/// #[methods(get, post)]
712/// async fn standalone_methods_handler(ctx: &Context) {}
713/// ```
714///
715/// The macro accepts a comma-separated list of HTTP method names (lowercase) and should be
716/// applied to async functions that accept a `&Context` parameter.
717#[proc_macro_attribute]
718pub fn methods(attr: TokenStream, item: TokenStream) -> TokenStream {
719    methods_macro(attr, item, Position::Prologue)
720}
721
722/// Restricts function execution to HTTP/0.9 requests only.
723///
724/// This attribute macro ensures the decorated function only executes for HTTP/0.9
725/// protocol requests, the earliest version of the HTTP protocol.
726///
727/// # Usage
728///
729/// ```rust
730/// use hyperlane::*;
731/// use hyperlane_macros::*;
732///
733/// #[route("/http0_9_version")]
734/// struct Http09;
735///
736/// impl ServerHook for Http09 {
737///     async fn new(_ctx: &Context) -> Self {
738///         Self
739///     }
740///
741///     #[prologue_macros(http0_9_version, response_body("http0_9_version"))]
742///     async fn handle(self, ctx: &Context) {}
743/// }
744///
745/// impl Http09 {
746///     #[http0_9_version]
747///     async fn http0_9_version_with_ref_self(&self, ctx: &Context) {}
748/// }
749///
750/// #[http0_9_version]
751/// async fn standalone_http0_9_version_handler(ctx: &Context) {}
752/// ```
753///
754/// The macro takes no parameters and should be applied directly to async functions
755/// that accept a `&Context` parameter.
756#[proc_macro_attribute]
757pub fn http0_9_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
758    http0_9_version_macro(item, Position::Prologue)
759}
760
761/// Restricts function execution to HTTP/1.0 requests only.
762///
763/// This attribute macro ensures the decorated function only executes for HTTP/1.0
764/// protocol requests.
765///
766/// # Usage
767///
768/// ```rust
769/// use hyperlane::*;
770/// use hyperlane_macros::*;
771///
772/// #[route("/http1_0_version")]
773/// struct Http10;
774///
775/// impl ServerHook for Http10 {
776///     async fn new(_ctx: &Context) -> Self {
777///         Self
778///     }
779///
780///     #[prologue_macros(http1_0_version, response_body("http1_0_version"))]
781///     async fn handle(self, ctx: &Context) {}
782/// }
783///
784/// impl Http10 {
785///     #[http1_0_version]
786///     async fn http1_0_version_with_ref_self(&self, ctx: &Context) {}
787/// }
788///
789/// #[http1_0_version]
790/// async fn standalone_http1_0_version_handler(ctx: &Context) {}
791/// ```
792///
793/// The macro takes no parameters and should be applied directly to async functions
794/// that accept a `&Context` parameter.
795#[proc_macro_attribute]
796pub fn http1_0_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
797    http1_0_version_macro(item, Position::Prologue)
798}
799
800/// Restricts function execution to HTTP/1.1 requests only.
801///
802/// This attribute macro ensures the decorated function only executes for HTTP/1.1
803/// protocol requests.
804///
805/// # Usage
806///
807/// ```rust
808/// use hyperlane::*;
809/// use hyperlane_macros::*;
810///
811/// #[route("/http1_1_version")]
812/// struct Http11;
813///
814/// impl ServerHook for Http11 {
815///     async fn new(_ctx: &Context) -> Self {
816///         Self
817///     }
818///
819///     #[prologue_macros(http1_1_version, response_body("http1_1_version"))]
820///     async fn handle(self, ctx: &Context) {}
821/// }
822///
823/// impl Http11 {
824///     #[http1_1_version]
825///     async fn http1_1_with_ref_self(&self, ctx: &Context) {}
826/// }
827///
828/// #[http1_1_version]
829/// async fn standalone_http1_1_handler(ctx: &Context) {}
830/// ```
831///
832/// The macro takes no parameters and should be applied directly to async functions
833/// that accept a `&Context` parameter.
834#[proc_macro_attribute]
835pub fn http1_1_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
836    http1_1_version_macro(item, Position::Prologue)
837}
838
839/// Restricts function execution to HTTP/2 requests only.
840///
841/// This attribute macro ensures the decorated function only executes for HTTP/2
842/// protocol requests.
843///
844/// # Usage
845///
846/// ```rust
847/// use hyperlane::*;
848/// use hyperlane_macros::*;
849///
850/// #[route("/http2_version")]
851/// struct Http2;
852///
853/// impl ServerHook for Http2 {
854///     async fn new(_ctx: &Context) -> Self {
855///         Self
856///     }
857///
858///     #[prologue_macros(http2_version, response_body("http2_version"))]
859///     async fn handle(self, ctx: &Context) {}
860/// }
861///
862/// impl Http2 {
863///     #[http2_version]
864///     async fn http2_version_with_ref_self(&self, ctx: &Context) {}
865/// }
866///
867/// #[http2_version]
868/// async fn standalone_http2_version_handler(ctx: &Context) {}
869/// ```
870///
871/// The macro takes no parameters and should be applied directly to async functions
872/// that accept a `&Context` parameter.
873#[proc_macro_attribute]
874pub fn http2_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
875    http2_version_macro(item, Position::Prologue)
876}
877
878/// Restricts function execution to HTTP/3 requests only.
879///
880/// This attribute macro ensures the decorated function only executes for HTTP/3
881/// protocol requests, the latest version of the HTTP protocol.
882///
883/// # Usage
884///
885/// ```rust
886/// use hyperlane::*;
887/// use hyperlane_macros::*;
888///
889/// #[route("/http3_version")]
890/// struct Http3;
891///
892/// impl ServerHook for Http3 {
893///     async fn new(_ctx: &Context) -> Self {
894///         Self
895///     }
896///
897///     #[prologue_macros(http3_version, response_body("http3_version"))]
898///     async fn handle(self, ctx: &Context) {}
899/// }
900///
901/// impl Http3 {
902///     #[http3_version]
903///     async fn http3_version_with_ref_self(&self, ctx: &Context) {}
904/// }
905///
906/// #[http3_version]
907/// async fn standalone_http3_version_handler(ctx: &Context) {}
908/// ```
909///
910/// The macro takes no parameters and should be applied directly to async functions
911/// that accept a `&Context` parameter.
912#[proc_macro_attribute]
913pub fn http3_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
914    http3_version_macro(item, Position::Prologue)
915}
916
917/// Restricts function execution to HTTP/1.1 or higher protocol versions.
918///
919/// This attribute macro ensures the decorated function only executes for HTTP/1.1
920/// or newer protocol versions, including HTTP/2, HTTP/3, and future versions.
921///
922/// # Usage
923///
924/// ```rust
925/// use hyperlane::*;
926/// use hyperlane_macros::*;
927///
928/// #[route("/http1_1_or_higher_version")]
929/// struct Http11OrHigher;
930///
931/// impl ServerHook for Http11OrHigher {
932///     async fn new(_ctx: &Context) -> Self {
933///         Self
934///     }
935///
936///     #[prologue_macros(http1_1_or_higher_version, response_body("http1_1_or_higher_version"))]
937///     async fn handle(self, ctx: &Context) {}
938/// }
939///
940/// impl Http11OrHigher {
941///     #[http1_1_or_higher_version]
942///     async fn http1_1_or_higher_version_with_ref_self(&self, ctx: &Context) {}
943/// }
944///
945/// #[http1_1_or_higher_version]
946/// async fn standalone_http1_1_or_higher_version_handler(ctx: &Context) {}
947/// ```
948///
949/// The macro takes no parameters and should be applied directly to async functions
950/// that accept a `&Context` parameter.
951#[proc_macro_attribute]
952pub fn http1_1_or_higher_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
953    http1_1_or_higher_version_macro(item, Position::Prologue)
954}
955
956/// Restricts function execution to standard HTTP requests only.
957///
958/// This attribute macro ensures the decorated function only executes for standard HTTP requests,
959/// excluding WebSocket upgrades and other protocol upgrade requests.
960///
961/// # Usage
962///
963/// ```rust
964/// use hyperlane::*;
965/// use hyperlane_macros::*;
966///
967/// #[route("/http")]
968/// struct HttpOnly;
969///
970/// impl ServerHook for HttpOnly {
971///     async fn new(_ctx: &Context) -> Self {
972///         Self
973///     }
974///
975///     #[prologue_macros(http_version, response_body("http"))]
976///     async fn handle(self, ctx: &Context) {}
977/// }
978///
979/// impl HttpOnly {
980///     #[http_version]
981///     async fn http_with_ref_self(&self, ctx: &Context) {}
982/// }
983///
984/// #[http_version]
985/// async fn standalone_http_handler(ctx: &Context) {}
986/// ```
987///
988/// The macro takes no parameters and should be applied directly to async functions
989/// that accept a `&Context` parameter.
990#[proc_macro_attribute]
991pub fn http_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
992    http_version_macro(item, Position::Prologue)
993}
994
995/// Restricts function execution to requests with unknown HTTP versions only.
996///
997/// This attribute macro ensures the decorated function only executes when the incoming request
998/// uses an unrecognized or non-standard HTTP version (not HTTP/0.9, HTTP/1.0, HTTP/1.1, HTTP/2, or HTTP/3).
999///
1000/// # Usage
1001///
1002/// ```rust
1003/// use hyperlane::*;
1004/// use hyperlane_macros::*;
1005///
1006/// #[route("/unknown_version")]
1007/// struct UnknownVersionHandler;
1008///
1009/// impl ServerHook for UnknownVersionHandler {
1010///     async fn new(_ctx: &Context) -> Self {
1011///         Self
1012///     }
1013///
1014///     #[prologue_macros(unknown_version, response_body("unknown version"))]
1015///     async fn handle(self, ctx: &Context) {}
1016/// }
1017///
1018/// impl UnknownVersionHandler {
1019///     #[unknown_version]
1020///     async fn handle_unknown_with_ref_self(&self, ctx: &Context) {}
1021/// }
1022///
1023/// #[unknown_version]
1024/// async fn standalone_unknown_version_handler(ctx: &Context) {}
1025/// ```
1026///
1027/// The macro takes no parameters and should be applied directly to async functions
1028/// that accept a `&Context` parameter.
1029#[proc_macro_attribute]
1030pub fn unknown_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
1031    unknown_version_macro(item, Position::Prologue)
1032}
1033
1034/// Restricts function execution to WebSocket upgrade requests only.
1035///
1036/// This attribute macro ensures the decorated function only executes when the incoming request
1037/// is a valid WebSocket upgrade request with proper request headers and protocol negotiation.
1038///
1039/// # Usage
1040///
1041/// ```rust
1042/// use hyperlane::*;
1043/// use hyperlane_macros::*;
1044///
1045/// #[route("/ws_upgrade_type")]
1046/// struct Websocket;
1047///
1048/// impl ServerHook for Websocket {
1049///     async fn new(_ctx: &Context) -> Self {
1050///         Self
1051///     }
1052///
1053///     #[ws_upgrade_type]
1054///     #[ws_from_stream]
1055///     async fn handle(self, ctx: &Context) {
1056///         let body: RequestBody = ctx.get_request_body().await;
1057///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
1058///         ctx.send_body_list_with_data(&body_list).await;
1059///     }
1060/// }
1061///
1062/// impl Websocket {
1063///     #[ws_upgrade_type]
1064///     async fn ws_with_ref_self(&self, ctx: &Context) {}
1065/// }
1066///
1067/// #[ws_upgrade_type]
1068/// async fn standalone_ws_handler(ctx: &Context) {}
1069/// ```
1070///
1071/// The macro takes no parameters and should be applied directly to async functions
1072/// that accept a `&Context` parameter.
1073#[proc_macro_attribute]
1074pub fn ws_upgrade_type(_attr: TokenStream, item: TokenStream) -> TokenStream {
1075    ws_upgrade_type_macro(item, Position::Prologue)
1076}
1077
1078/// Restricts function execution to HTTP/2 Cleartext (h2c_upgrade_type) requests only.
1079///
1080/// This attribute macro ensures the decorated function only executes for HTTP/2 cleartext
1081/// requests that use the h2c_upgrade_type upgrade mechanism.
1082///
1083/// # Usage
1084///
1085/// ```rust
1086/// use hyperlane::*;
1087/// use hyperlane_macros::*;
1088///
1089/// #[route("/h2c_upgrade_type")]
1090/// struct H2c;
1091///
1092/// impl ServerHook for H2c {
1093///     async fn new(_ctx: &Context) -> Self {
1094///         Self
1095///     }
1096///
1097///     #[prologue_macros(h2c_upgrade_type, response_body("h2c_upgrade_type"))]
1098///     async fn handle(self, ctx: &Context) {}
1099/// }
1100///
1101/// impl H2c {
1102///     #[h2c_upgrade_type]
1103///     async fn h2c_upgrade_type_with_ref_self(&self, ctx: &Context) {}
1104/// }
1105///
1106/// #[h2c_upgrade_type]
1107/// async fn standalone_h2c_upgrade_type_handler(ctx: &Context) {}
1108/// ```
1109///
1110/// The macro takes no parameters and should be applied directly to async functions
1111/// that accept a `&Context` parameter.
1112#[proc_macro_attribute]
1113pub fn h2c_upgrade_type(_attr: TokenStream, item: TokenStream) -> TokenStream {
1114    h2c_upgrade_type_macro(item, Position::Prologue)
1115}
1116
1117/// Restricts function execution to TLS-encrypted requests only.
1118///
1119/// This attribute macro ensures the decorated function only executes for requests
1120/// that use TLS/SSL encryption on the connection.
1121///
1122/// # Usage
1123///
1124/// ```rust
1125/// use hyperlane::*;
1126/// use hyperlane_macros::*;
1127///
1128/// #[route("/tls_upgrade_type")]
1129/// struct Tls;
1130///
1131/// impl ServerHook for Tls {
1132///     async fn new(_ctx: &Context) -> Self {
1133///         Self
1134///     }
1135///
1136///     #[prologue_macros(tls_upgrade_type, response_body("tls_upgrade_type"))]
1137///     async fn handle(self, ctx: &Context) {}
1138/// }
1139///
1140/// impl Tls {
1141///     #[tls_upgrade_type]
1142///     async fn tls_upgrade_type_with_ref_self(&self, ctx: &Context) {}
1143/// }
1144///
1145/// #[tls_upgrade_type]
1146/// async fn standalone_tls_upgrade_type_handler(ctx: &Context) {}
1147/// ```
1148///
1149/// The macro takes no parameters and should be applied directly to async functions
1150/// that accept a `&Context` parameter.
1151#[proc_macro_attribute]
1152pub fn tls_upgrade_type(_attr: TokenStream, item: TokenStream) -> TokenStream {
1153    tls_upgrade_type_macro(item, Position::Prologue)
1154}
1155
1156/// Restricts function execution to requests with unknown protocol upgrade types only.
1157///
1158/// This attribute macro ensures the decorated function only executes when the incoming request
1159/// uses an unrecognized or non-standard protocol upgrade type (not WebSocket, h2c, or TLS).
1160///
1161/// # Usage
1162///
1163/// ```rust
1164/// use hyperlane::*;
1165/// use hyperlane_macros::*;
1166///
1167/// #[route("/unknown_upgrade_type")]
1168/// struct UnknownUpgrade;
1169///
1170/// impl ServerHook for UnknownUpgrade {
1171///     async fn new(_ctx: &Context) -> Self {
1172///         Self
1173///     }
1174///
1175///     #[prologue_macros(unknown_upgrade_type, response_body("unknown upgrade type"))]
1176///     async fn handle(self, ctx: &Context) {}
1177/// }
1178///
1179/// impl UnknownUpgrade {
1180///     #[unknown_upgrade_type]
1181///     async fn unknown_upgrade_type_with_ref_self(&self, ctx: &Context) {}
1182/// }
1183///
1184/// #[unknown_upgrade_type]
1185/// async fn standalone_unknown_upgrade_type_handler(ctx: &Context) {}
1186/// ```
1187///
1188/// The macro takes no parameters and should be applied directly to async functions
1189/// that accept a `&Context` parameter.
1190#[proc_macro_attribute]
1191pub fn unknown_upgrade_type(_attr: TokenStream, item: TokenStream) -> TokenStream {
1192    unknown_upgrade_type_macro(item, Position::Prologue)
1193}
1194
1195/// Sets the HTTP status code for the response.
1196///
1197/// This attribute macro configures the HTTP status code that will be sent with the response.
1198/// The status code can be provided as a numeric literal or a global constant.
1199///
1200/// # Usage
1201///
1202/// ```rust
1203/// use hyperlane::*;
1204/// use hyperlane_macros::*;
1205///
1206/// const CUSTOM_STATUS_CODE: i32 = 200;
1207///
1208/// #[route("/response_status_code")]
1209/// struct ResponseStatusCode;
1210///
1211/// impl ServerHook for ResponseStatusCode {
1212///     async fn new(_ctx: &Context) -> Self {
1213///         Self
1214///     }
1215///
1216///     #[response_status_code(CUSTOM_STATUS_CODE)]
1217///     async fn handle(self, ctx: &Context) {}
1218/// }
1219///
1220/// impl ResponseStatusCode {
1221///     #[response_status_code(CUSTOM_STATUS_CODE)]
1222///     async fn response_status_code_with_ref_self(&self, ctx: &Context) {}
1223/// }
1224///
1225/// #[response_status_code(200)]
1226/// async fn standalone_response_status_code_handler(ctx: &Context) {}
1227/// ```
1228///
1229/// The macro accepts a numeric HTTP status code or a global constant
1230/// and should be applied to async functions that accept a `&Context` parameter.
1231#[proc_macro_attribute]
1232pub fn response_status_code(attr: TokenStream, item: TokenStream) -> TokenStream {
1233    response_status_code_macro(attr, item, Position::Prologue)
1234}
1235
1236/// Sets the HTTP reason phrase for the response.
1237///
1238/// This attribute macro configures the HTTP reason phrase that accompanies the status code.
1239/// The reason phrase can be provided as a string literal or a global constant.
1240///
1241/// # Usage
1242///
1243/// ```rust
1244/// use hyperlane::*;
1245/// use hyperlane_macros::*;
1246///
1247/// const CUSTOM_REASON: &str = "Accepted";
1248///
1249/// #[route("/response_reason")]
1250/// struct ResponseReason;
1251///
1252/// impl ServerHook for ResponseReason {
1253///     async fn new(_ctx: &Context) -> Self {
1254///         Self
1255///     }
1256///
1257///     #[response_reason_phrase(CUSTOM_REASON)]
1258///     async fn handle(self, ctx: &Context) {}
1259/// }
1260///
1261/// impl ResponseReason {
1262///     #[response_reason_phrase(CUSTOM_REASON)]
1263///     async fn response_reason_phrase_with_ref_self(&self, ctx: &Context) {}
1264/// }
1265///
1266/// #[response_reason_phrase("OK")]
1267/// async fn standalone_response_reason_phrase_handler(ctx: &Context) {}
1268/// ```
1269///
1270/// The macro accepts a string literal or global constant for the reason phrase and should be
1271/// applied to async functions that accept a `&Context` parameter.
1272#[proc_macro_attribute]
1273pub fn response_reason_phrase(attr: TokenStream, item: TokenStream) -> TokenStream {
1274    response_reason_phrase_macro(attr, item, Position::Prologue)
1275}
1276
1277/// Sets or replaces a specific HTTP response header.
1278///
1279/// This attribute macro configures a specific HTTP response header that will be sent with the response.
1280/// Both the header name and value can be provided as string literals or global constants.
1281/// Use `"key", "value"` to set a header (add to existing headers) or `"key" => "value"` to replace a header (overwrite existing).
1282///
1283/// # Usage
1284///
1285/// ```rust
1286/// use hyperlane::*;
1287/// use hyperlane_macros::*;
1288///
1289/// const CUSTOM_HEADER_NAME: &str = "X-Custom-Header";
1290/// const CUSTOM_HEADER_VALUE: &str = "custom-value";
1291///
1292/// #[route("/response_header")]
1293/// struct ResponseHeader;
1294///
1295/// impl ServerHook for ResponseHeader {
1296///     async fn new(_ctx: &Context) -> Self {
1297///         Self
1298///     }
1299///
1300///     #[response_header(CUSTOM_HEADER_NAME => CUSTOM_HEADER_VALUE)]
1301///     async fn handle(self, ctx: &Context) {}
1302/// }
1303///
1304/// impl ResponseHeader {
1305///     #[response_header(CUSTOM_HEADER_NAME => CUSTOM_HEADER_VALUE)]
1306///     async fn response_header_with_ref_self(&self, ctx: &Context) {}
1307/// }
1308///
1309/// #[route("/response_header")]
1310/// struct ResponseHeaderTest;
1311///
1312/// impl ServerHook for ResponseHeaderTest {
1313///     async fn new(_ctx: &Context) -> Self {
1314///         Self
1315///     }
1316///
1317///     #[response_body("Testing header set and replace operations")]
1318///     #[response_header("X-Add-Header", "add-value")]
1319///     #[response_header("X-Set-Header" => "set-value")]
1320///     async fn handle(self, ctx: &Context) {}
1321/// }
1322///
1323/// #[response_header("X-Custom" => "value")]
1324/// async fn standalone_response_header_handler(ctx: &Context) {}
1325/// ```
1326///
1327/// The macro accepts header name and header value, both can be string literals or global constants.
1328/// Use `"key", "value"` for setting headers and `"key" => "value"` for replacing headers.
1329/// Should be applied to async functions that accept a `&Context` parameter.
1330#[proc_macro_attribute]
1331pub fn response_header(attr: TokenStream, item: TokenStream) -> TokenStream {
1332    response_header_macro(attr, item, Position::Prologue)
1333}
1334
1335/// Sets the HTTP response body.
1336///
1337/// This attribute macro configures the HTTP response body that will be sent with the response.
1338/// The body content can be provided as a string literal or a global constant.
1339///
1340/// # Usage
1341///
1342/// ```rust
1343/// use hyperlane::*;
1344/// use hyperlane_macros::*;
1345///
1346/// const RESPONSE_DATA: &str = "{\"status\": \"success\"}";
1347///
1348/// #[route("/response_body")]
1349/// struct ResponseBody;
1350///
1351/// impl ServerHook for ResponseBody {
1352///     async fn new(_ctx: &Context) -> Self {
1353///         Self
1354///     }
1355///
1356///     #[response_body(&RESPONSE_DATA)]
1357///     async fn handle(self, ctx: &Context) {}
1358/// }
1359///
1360/// impl ResponseBody {
1361///     #[response_body(&RESPONSE_DATA)]
1362///     async fn response_body_with_ref_self(&self, ctx: &Context) {}
1363/// }
1364///
1365/// #[response_body("standalone response body")]
1366/// async fn standalone_response_body_handler(ctx: &Context) {}
1367/// ```
1368///
1369/// The macro accepts a string literal or global constant for the response body and should be
1370/// applied to async functions that accept a `&Context` parameter.
1371#[proc_macro_attribute]
1372pub fn response_body(attr: TokenStream, item: TokenStream) -> TokenStream {
1373    response_body_macro(attr, item, Position::Prologue)
1374}
1375
1376/// Clears all response headers.
1377///
1378/// This attribute macro clears all response headers from the response.
1379///
1380/// # Usage
1381///
1382/// ```rust
1383/// use hyperlane::*;
1384/// use hyperlane_macros::*;
1385///
1386/// #[route("/clear_response_headers")]
1387/// struct ClearResponseHeaders;
1388///
1389/// impl ServerHook for ClearResponseHeaders {
1390///     async fn new(_ctx: &Context) -> Self {
1391///         Self
1392///     }
1393///
1394///     #[prologue_macros(
1395///         clear_response_headers,
1396///         filter(ctx.get_request().await.is_unknown_method()),
1397///         response_body("clear_response_headers")
1398///     )]
1399///     async fn handle(self, ctx: &Context) {}
1400/// }
1401///
1402/// impl ClearResponseHeaders {
1403///     #[clear_response_headers]
1404///     async fn clear_response_headers_with_ref_self(&self, ctx: &Context) {}
1405/// }
1406///
1407/// #[clear_response_headers]
1408/// async fn standalone_clear_response_headers_handler(ctx: &Context) {}
1409/// ```
1410///
1411/// The macro should be applied to async functions that accept a `&Context` parameter.   
1412#[proc_macro_attribute]
1413pub fn clear_response_headers(_attr: TokenStream, item: TokenStream) -> TokenStream {
1414    clear_response_headers_macro(item, Position::Prologue)
1415}
1416
1417/// Sets the HTTP response version.
1418///
1419/// This attribute macro configures the HTTP response version that will be sent with the response.
1420/// The version can be provided as a variable or code block.
1421///
1422/// # Usage
1423///
1424/// ```rust
1425/// use hyperlane::*;
1426/// use hyperlane_macros::*;
1427///
1428/// #[request_middleware]
1429/// struct RequestMiddleware;
1430///
1431/// impl ServerHook for RequestMiddleware {
1432///     async fn new(_ctx: &Context) -> Self {
1433///         Self
1434///     }
1435///
1436///     #[epilogue_macros(
1437///         response_status_code(200),
1438///         response_version(HttpVersion::Http1_1),
1439///         response_header(SERVER => HYPERLANE)
1440///     )]
1441///     async fn handle(self, ctx: &Context) {}
1442/// }
1443/// ```
1444///
1445/// The macro accepts a variable or code block for the response version and should be
1446/// applied to async functions that accept a `&Context` parameter.
1447#[proc_macro_attribute]
1448pub fn response_version(attr: TokenStream, item: TokenStream) -> TokenStream {
1449    response_version_macro(attr, item, Position::Prologue)
1450}
1451
1452/// Handles aborted request scenarios.
1453///
1454/// This attribute macro configures the function to handle cases where the client has
1455/// aborted the request, providing appropriate handling for interrupted or cancelled requests.
1456///
1457/// # Usage
1458///
1459/// ```rust
1460/// use hyperlane::*;
1461/// use hyperlane_macros::*;
1462///
1463/// #[route("/aborted")]
1464/// struct Aborted;
1465///
1466/// impl ServerHook for Aborted {
1467///     async fn new(_ctx: &Context) -> Self {
1468///         Self
1469///     }
1470///
1471///     #[aborted]
1472///     async fn handle(self, ctx: &Context) {}
1473/// }
1474///
1475/// impl Aborted {
1476///     #[aborted]
1477///     async fn aborted_with_ref_self(&self, ctx: &Context) {}
1478/// }
1479///
1480/// #[aborted]
1481/// async fn standalone_aborted_handler(ctx: &Context) {}
1482/// ```
1483///
1484/// The macro takes no parameters and should be applied directly to async functions
1485/// that accept a `&Context` parameter.
1486#[proc_macro_attribute]
1487pub fn aborted(_attr: TokenStream, item: TokenStream) -> TokenStream {
1488    aborted_macro(item, Position::Prologue)
1489}
1490
1491/// Handles closed connection scenarios.
1492///
1493/// This attribute macro configures the function to handle cases where the connection
1494/// has been closed, providing appropriate handling for terminated or disconnected connections.
1495///
1496/// # Usage
1497///
1498/// ```rust
1499/// use hyperlane::*;
1500/// use hyperlane_macros::*;
1501///
1502/// #[route("/closed")]
1503/// struct ClosedTest;
1504///
1505/// impl ServerHook for ClosedTest {
1506///     async fn new(_ctx: &Context) -> Self {
1507///         Self
1508///     }
1509///
1510///     #[closed]
1511///     async fn handle(self, ctx: &Context) {}
1512/// }
1513///
1514/// impl ClosedTest {
1515///     #[closed]
1516///     async fn closed_with_ref_self(&self, ctx: &Context) {}
1517/// }
1518///
1519/// #[closed]
1520/// async fn standalone_closed_handler(ctx: &Context) {}
1521/// ```
1522///
1523/// The macro takes no parameters and should be applied directly to async functions
1524/// that accept a `&Context` parameter.
1525#[proc_macro_attribute]
1526pub fn closed(_attr: TokenStream, item: TokenStream) -> TokenStream {
1527    closed_macro(item, Position::Prologue)
1528}
1529
1530/// Filters requests based on a boolean condition.
1531///
1532/// The function continues execution only if the provided code block returns `true`.
1533///
1534/// # Usage
1535///
1536/// ```rust
1537/// use hyperlane::*;
1538/// use hyperlane_macros::*;
1539///
1540/// #[route("/unknown_method")]
1541/// struct UnknownMethod;
1542///
1543/// impl ServerHook for UnknownMethod {
1544///     async fn new(_ctx: &Context) -> Self {
1545///         Self
1546///     }
1547///
1548///     #[prologue_macros(
1549///         filter(ctx.get_request().await.is_unknown_method()),
1550///         response_body("unknown_method")
1551///     )]
1552///     async fn handle(self, ctx: &Context) {}
1553/// }
1554/// ```
1555#[proc_macro_attribute]
1556pub fn filter(attr: TokenStream, item: TokenStream) -> TokenStream {
1557    filter_macro(attr, item, Position::Prologue)
1558}
1559
1560/// Rejects requests based on a boolean condition.
1561///
1562/// The function continues execution only if the provided code block returns `false`.
1563///
1564/// # Usage
1565///
1566/// ```rust
1567/// use hyperlane::*;
1568/// use hyperlane_macros::*;
1569///
1570/// #[response_middleware(2)]
1571/// struct ResponseMiddleware2;
1572///
1573/// impl ServerHook for ResponseMiddleware2 {
1574///     async fn new(_ctx: &Context) -> Self {
1575///         Self
1576///     }
1577///
1578///     #[prologue_macros(
1579///         reject(ctx.get_request_is_ws_upgrade_type().await)
1580///     )]
1581///     async fn handle(self, ctx: &Context) {}
1582/// }
1583/// ```
1584#[proc_macro_attribute]
1585pub fn reject(attr: TokenStream, item: TokenStream) -> TokenStream {
1586    reject_macro(attr, item, Position::Prologue)
1587}
1588
1589/// Restricts function execution to requests with a specific host.
1590///
1591/// This attribute macro ensures the decorated function only executes when the incoming request
1592/// has a host header that matches the specified value. Requests with different or missing host headers will be filtered out.
1593///
1594/// # Usage
1595///
1596/// ```rust
1597/// use hyperlane::*;
1598/// use hyperlane_macros::*;
1599///
1600/// #[route("/host")]
1601/// struct Host;
1602///
1603/// impl ServerHook for Host {
1604///     async fn new(_ctx: &Context) -> Self {
1605///         Self
1606///     }
1607///
1608///     #[host("localhost")]
1609///     #[prologue_macros(response_body("host string literal: localhost"), send)]
1610///     async fn handle(self, ctx: &Context) {}
1611/// }
1612///
1613/// impl Host {
1614///     #[host("localhost")]
1615///     async fn host_with_ref_self(&self, ctx: &Context) {}
1616/// }
1617///
1618/// #[host("localhost")]
1619/// async fn standalone_host_handler(ctx: &Context) {}
1620/// ```
1621///
1622/// The macro accepts a string literal specifying the expected host value and should be
1623/// applied to async functions that accept a `&Context` parameter.
1624#[proc_macro_attribute]
1625pub fn host(attr: TokenStream, item: TokenStream) -> TokenStream {
1626    host_macro(attr, item, Position::Prologue)
1627}
1628
1629/// Reject requests that have no host header.
1630///
1631/// This attribute macro ensures the decorated function only executes when the incoming request
1632/// has a host header present. Requests without a host header will be filtered out.
1633///
1634/// # Usage
1635///
1636/// ```rust
1637/// use hyperlane::*;
1638/// use hyperlane_macros::*;
1639///
1640/// #[route("/reject_host")]
1641/// struct RejectHost;
1642///
1643/// impl ServerHook for RejectHost {
1644///     async fn new(_ctx: &Context) -> Self {
1645///         Self
1646///     }
1647///
1648///     #[prologue_macros(
1649///         reject_host("filter.localhost"),
1650///         response_body("host filter string literal")
1651///     )]
1652///     async fn handle(self, ctx: &Context) {}
1653/// }
1654///
1655/// impl RejectHost {
1656///     #[reject_host("filter.localhost")]
1657///     async fn reject_host_with_ref_self(&self, ctx: &Context) {}
1658/// }
1659///
1660/// #[reject_host("filter.localhost")]
1661/// async fn standalone_reject_host_handler(ctx: &Context) {}
1662/// ```
1663///
1664/// The macro takes no parameters and should be applied directly to async functions
1665/// that accept a `&Context` parameter.
1666#[proc_macro_attribute]
1667pub fn reject_host(attr: TokenStream, item: TokenStream) -> TokenStream {
1668    reject_host_macro(attr, item, Position::Prologue)
1669}
1670
1671/// Restricts function execution to requests with a specific referer.
1672///
1673/// This attribute macro ensures the decorated function only executes when the incoming request
1674/// has a referer header that matches the specified value. Requests with different or missing referer headers will be filtered out.
1675///
1676/// # Usage
1677///
1678/// ```rust
1679/// use hyperlane::*;
1680/// use hyperlane_macros::*;
1681///
1682/// #[route("/referer")]
1683/// struct Referer;
1684///
1685/// impl ServerHook for Referer {
1686///     async fn new(_ctx: &Context) -> Self {
1687///         Self
1688///     }
1689///
1690///     #[prologue_macros(
1691///         referer("http://localhost"),
1692///         response_body("referer string literal: http://localhost")
1693///     )]
1694///     async fn handle(self, ctx: &Context) {}
1695/// }
1696///
1697/// impl Referer {
1698///     #[referer("http://localhost")]
1699///     async fn referer_with_ref_self(&self, ctx: &Context) {}
1700/// }
1701///
1702/// #[referer("http://localhost")]
1703/// async fn standalone_referer_handler(ctx: &Context) {}
1704/// ```
1705///
1706/// The macro accepts a string literal specifying the expected referer value and should be
1707/// applied to async functions that accept a `&Context` parameter.
1708#[proc_macro_attribute]
1709pub fn referer(attr: TokenStream, item: TokenStream) -> TokenStream {
1710    referer_macro(attr, item, Position::Prologue)
1711}
1712
1713/// Reject requests that have a specific referer header.
1714///
1715/// This attribute macro ensures the decorated function only executes when the incoming request
1716/// does not have a referer header that matches the specified value. Requests with the matching referer header will be filtered out.
1717///
1718/// # Usage
1719///
1720/// ```rust
1721/// use hyperlane::*;
1722/// use hyperlane_macros::*;
1723///
1724/// #[route("/reject_referer")]
1725/// struct RejectReferer;
1726///
1727/// impl ServerHook for RejectReferer {
1728///     async fn new(_ctx: &Context) -> Self {
1729///         Self
1730///     }
1731///
1732///     #[prologue_macros(
1733///         reject_referer("http://localhost"),
1734///         response_body("referer filter string literal")
1735///     )]
1736///     async fn handle(self, ctx: &Context) {}
1737/// }
1738///
1739/// impl RejectReferer {
1740///     #[reject_referer("http://localhost")]
1741///     async fn reject_referer_with_ref_self(&self, ctx: &Context) {}
1742/// }
1743///
1744/// #[reject_referer("http://localhost")]
1745/// async fn standalone_reject_referer_handler(ctx: &Context) {}
1746/// ```
1747///
1748/// The macro accepts a string literal specifying the referer value to filter out and should be
1749/// applied to async functions that accept a `&Context` parameter.
1750#[proc_macro_attribute]
1751pub fn reject_referer(attr: TokenStream, item: TokenStream) -> TokenStream {
1752    reject_referer_macro(attr, item, Position::Prologue)
1753}
1754
1755/// Executes multiple specified functions before the main handler function.
1756///
1757/// This attribute macro configures multiple pre-execution hooks that run before the main function logic.
1758/// The specified hook functions will be called in the order provided, followed by the main function execution.
1759///
1760/// # Usage
1761///
1762/// ```rust
1763/// use hyperlane::*;
1764/// use hyperlane_macros::*;
1765///
1766/// struct PrologueHooks;
1767///
1768/// impl ServerHook for PrologueHooks {
1769///     async fn new(_ctx: &Context) -> Self {
1770///         Self
1771///     }
1772///
1773///     #[get_method]
1774///     #[http_version]
1775///     async fn handle(self, _ctx: &Context) {}
1776/// }
1777///
1778/// async fn prologue_hooks_fn(ctx: &Context) {
1779///     let hook = PrologueHooks::new(&ctx).await;
1780///     hook.handle(&ctx).await;
1781/// }
1782///
1783/// #[route("/hook")]
1784/// struct Hook;
1785///
1786/// impl ServerHook for Hook {
1787///     async fn new(_ctx: &Context) -> Self {
1788///         Self
1789///     }
1790///
1791///     #[prologue_hooks(prologue_hooks_fn)]
1792///     #[response_body("Testing hook macro")]
1793///     async fn handle(self, ctx: &Context) {}
1794/// }
1795/// ```
1796///
1797/// The macro accepts a comma-separated list of function names as parameters. All hook functions
1798/// and the main function must accept a `Context` parameter. Avoid combining this macro with other
1799/// macros on the same function to prevent macro expansion conflicts.
1800///
1801/// # Advanced Usage with Method Expressions
1802///
1803/// ```rust
1804/// use hyperlane::*;
1805/// use hyperlane_macros::*;
1806///
1807/// #[route("/hooks_expression")]
1808/// struct HooksExpression;
1809///
1810/// impl ServerHook for HooksExpression {
1811///     async fn new(_ctx: &Context) -> Self {
1812///         Self
1813///     }
1814///
1815///     #[get_method]
1816///     #[prologue_hooks(HooksExpression::new_hook, HooksExpression::method_hook)]
1817///     #[response_body("hooks expression test")]
1818///     async fn handle(self, ctx: &Context) {}
1819/// }
1820///
1821/// impl HooksExpression {
1822///     async fn new_hook(_ctx: &Context) {}
1823///
1824///     async fn method_hook(_ctx: &Context) {}
1825/// }
1826/// ```
1827#[proc_macro_attribute]
1828pub fn prologue_hooks(attr: TokenStream, item: TokenStream) -> TokenStream {
1829    prologue_hooks_macro(attr, item, Position::Prologue)
1830}
1831
1832/// Executes multiple specified functions after the main handler function.
1833///
1834/// This attribute macro configures multiple post-execution hooks that run after the main function logic.
1835/// The main function will execute first, followed by the specified hook functions in the order provided.
1836///
1837/// # Usage
1838///
1839/// ```rust
1840/// use hyperlane::*;
1841/// use hyperlane_macros::*;
1842///
1843/// struct EpilogueHooks;
1844///
1845/// impl ServerHook for EpilogueHooks {
1846///     async fn new(_ctx: &Context) -> Self {
1847///         Self
1848///     }
1849///
1850///     #[response_status_code(200)]
1851///     async fn handle(self, ctx: &Context) {}
1852/// }
1853///
1854/// async fn epilogue_hooks_fn(ctx: &Context) {
1855///     let hook = EpilogueHooks::new(&ctx).await;
1856///     hook.handle(&ctx).await;
1857/// }
1858///
1859/// #[route("/hook")]
1860/// struct Hook;
1861///
1862/// impl ServerHook for Hook {
1863///     async fn new(_ctx: &Context) -> Self {
1864///         Self
1865///     }
1866///
1867///     #[epilogue_hooks(epilogue_hooks_fn)]
1868///     #[response_body("Testing hook macro")]
1869///     async fn handle(self, ctx: &Context) {}
1870/// }
1871///
1872/// ```
1873///
1874/// The macro accepts a comma-separated list of function names as parameters. All hook functions
1875/// and the main function must accept a `Context` parameter. Avoid combining this macro with other
1876/// macros on the same function to prevent macro expansion conflicts.
1877///
1878/// # Advanced Usage with Method Expressions
1879///
1880/// ```rust
1881/// use hyperlane::*;
1882/// use hyperlane_macros::*;
1883///
1884/// #[route("/hooks_expression")]
1885/// struct HooksExpression;
1886///
1887/// impl ServerHook for HooksExpression {
1888///     async fn new(_ctx: &Context) -> Self {
1889///         Self
1890///     }
1891///
1892///     #[get_method]
1893///     #[epilogue_hooks(HooksExpression::new_hook, HooksExpression::method_hook)]
1894///     #[response_body("hooks expression test")]
1895///     async fn handle(self, ctx: &Context) {}
1896/// }
1897///
1898/// impl HooksExpression {
1899///     async fn new_hook(_ctx: &Context) {}
1900///
1901///     async fn method_hook(_ctx: &Context) {}
1902/// }
1903/// ```
1904#[proc_macro_attribute]
1905pub fn epilogue_hooks(attr: TokenStream, item: TokenStream) -> TokenStream {
1906    epilogue_hooks_macro(attr, item, Position::Epilogue)
1907}
1908
1909/// Extracts the raw request body into a specified variable.
1910///
1911/// This attribute macro extracts the raw request body content into a variable
1912/// with the fixed type `RequestBody`. The body content is not parsed or deserialized.
1913///
1914/// # Usage
1915///
1916/// ```rust
1917/// use hyperlane::*;
1918/// use hyperlane_macros::*;
1919///
1920/// #[route("/request_body")]
1921/// struct RequestBodyRoute;
1922///
1923/// impl ServerHook for RequestBodyRoute {
1924///     async fn new(_ctx: &Context) -> Self {
1925///         Self
1926///     }
1927///
1928///     #[response_body(&format!("raw body: {raw_body:?}"))]
1929///     #[request_body(raw_body)]
1930///     async fn handle(self, ctx: &Context) {}
1931/// }
1932///
1933/// impl RequestBodyRoute {
1934///     #[request_body(raw_body)]
1935///     async fn request_body_with_ref_self(&self, ctx: &Context) {}
1936/// }
1937///
1938/// #[request_body(raw_body)]
1939/// async fn standalone_request_body_handler(ctx: &Context) {}
1940/// ```
1941///
1942/// # Multi-Parameter Usage
1943///
1944/// ```rust
1945/// use hyperlane::*;
1946/// use hyperlane_macros::*;
1947///
1948/// #[route("/multi_body")]
1949/// struct MultiBody;
1950///
1951/// impl ServerHook for MultiBody {
1952///     async fn new(_ctx: &Context) -> Self {
1953///         Self
1954///     }
1955///
1956///     #[response_body(&format!("bodies: {body1:?}, {body2:?}"))]
1957///     #[request_body(body1, body2)]
1958///     async fn handle(self, ctx: &Context) {}
1959/// }
1960/// ```
1961///
1962/// The macro accepts one or more variable names separated by commas.
1963/// Each variable will be available in the function scope as a `RequestBody` type.
1964#[proc_macro_attribute]
1965pub fn request_body(attr: TokenStream, item: TokenStream) -> TokenStream {
1966    request_body_macro(attr, item, Position::Prologue)
1967}
1968
1969/// Parses the request body as JSON into a specified variable and type with panic on parsing failure.
1970///
1971/// This attribute macro extracts and deserializes the request body content as JSON into a variable
1972/// with the specified type. The body content is parsed as JSON using serde.
1973/// If the request body does not exist or JSON parsing fails, the function will panic with an error message.
1974///
1975/// # Usage
1976///
1977/// ```rust
1978/// use hyperlane::*;
1979/// use hyperlane_macros::*;
1980/// use serde::{Deserialize, Serialize};
1981///
1982/// #[derive(Debug, Serialize, Deserialize, Clone)]
1983/// struct TestData {
1984///     name: String,
1985///     age: u32,
1986/// }
1987///
1988/// #[route("/request_body_json_result")]
1989/// struct RequestBodyJson;
1990///
1991/// impl ServerHook for RequestBodyJson {
1992///     async fn new(_ctx: &Context) -> Self {
1993///         Self
1994///     }
1995///
1996///     #[response_body(&format!("request data: {request_data_result:?}"))]
1997///     #[request_body_json_result(request_data_result: TestData)]
1998///     async fn handle(self, ctx: &Context) {}
1999/// }
2000///
2001/// impl RequestBodyJson {
2002///     #[request_body_json_result(request_data_result: TestData)]
2003///     async fn request_body_json_with_ref_self(&self, ctx: &Context) {}
2004/// }
2005///
2006/// #[request_body_json_result(request_data_result: TestData)]
2007/// async fn standalone_request_body_json_handler(ctx: &Context) {}
2008/// ```
2009///
2010/// # Multi-Parameter Usage
2011///
2012/// ```rust
2013/// use hyperlane::*;
2014/// use hyperlane_macros::*;
2015/// use serde::{Deserialize, Serialize};
2016///
2017/// #[derive(Debug, Serialize, Deserialize, Clone)]
2018/// struct User {
2019///     name: String,
2020/// }
2021///
2022/// #[derive(Debug, Serialize, Deserialize, Clone)]
2023/// struct Config {
2024///     debug: bool,
2025/// }
2026///
2027/// #[route("/request_body_json_result")]
2028/// struct TestData;
2029///
2030/// impl ServerHook for TestData {
2031///     async fn new(_ctx: &Context) -> Self {
2032///         Self
2033///     }
2034///
2035///     #[response_body(&format!("user: {user:?}, config: {config:?}"))]
2036///     #[request_body_json_result(user: User, config: Config)]
2037///     async fn handle(self, ctx: &Context) {}
2038/// }
2039/// ```
2040///
2041/// The macro accepts one or more `variable_name: Type` pairs separated by commas.
2042/// Each variable will be available in the function scope as a `Result<Type, serde_json::Error>`.
2043#[proc_macro_attribute]
2044pub fn request_body_json_result(attr: TokenStream, item: TokenStream) -> TokenStream {
2045    request_body_json_result_macro(attr, item, Position::Prologue)
2046}
2047
2048/// Parses the request body as JSON into a specified variable and type with panic on parsing failure.
2049///
2050/// This attribute macro extracts and deserializes the request body content as JSON into a variable
2051/// with the specified type. The body content is parsed as JSON using serde.
2052/// If the request body does not exist or JSON parsing fails, the function will panic with an error message.
2053///
2054/// # Usage
2055///
2056/// ```rust
2057/// use hyperlane::*;
2058/// use hyperlane_macros::*;
2059/// use serde::{Deserialize, Serialize};
2060///
2061/// #[derive(Debug, Serialize, Deserialize, Clone)]
2062/// struct TestData {
2063///     name: String,
2064///     age: u32,
2065/// }
2066///
2067/// #[route("/request_body_json")]
2068/// struct RequestBodyJson;
2069///
2070/// impl ServerHook for RequestBodyJson {
2071///     async fn new(_ctx: &Context) -> Self {
2072///         Self
2073///     }
2074///
2075///     #[response_body(&format!("request data: {request_data_result:?}"))]
2076///     #[request_body_json(request_data_result: TestData)]
2077///     async fn handle(self, ctx: &Context) {}
2078/// }
2079///
2080/// impl RequestBodyJson {
2081///     #[request_body_json(request_data_result: TestData)]
2082///     async fn request_body_json_with_ref_self(&self, ctx: &Context) {}
2083/// }
2084///
2085/// #[request_body_json(request_data_result: TestData)]
2086/// async fn standalone_request_body_json_handler(ctx: &Context) {}
2087/// ```
2088///
2089/// # Multi-Parameter Usage
2090///
2091/// ```rust
2092/// use hyperlane::*;
2093/// use hyperlane_macros::*;
2094/// use serde::{Deserialize, Serialize};
2095///
2096/// #[derive(Debug, Serialize, Deserialize, Clone)]
2097/// struct User {
2098///     name: String,
2099/// }
2100///
2101/// #[derive(Debug, Serialize, Deserialize, Clone)]
2102/// struct Config {
2103///     debug: bool,
2104/// }
2105///
2106/// #[route("/request_body_json")]
2107/// struct TestData;
2108///
2109/// impl ServerHook for TestData {
2110///     async fn new(_ctx: &Context) -> Self {
2111///         Self
2112///     }
2113///
2114///     #[response_body(&format!("user: {user:?}, config: {config:?}"))]
2115///     #[request_body_json(user: User, config: Config)]
2116///     async fn handle(self, ctx: &Context) {}
2117/// }
2118/// ```
2119///
2120/// The macro accepts one or more `variable_name: Type` pairs separated by commas.
2121/// Each variable will be available in the function scope as a `Result<Type, serde_json::Error>`.
2122///
2123/// # Panics
2124///
2125/// This macro will panic if the request body does not exist or JSON parsing fails.
2126#[proc_macro_attribute]
2127pub fn request_body_json(attr: TokenStream, item: TokenStream) -> TokenStream {
2128    request_body_json_macro(attr, item, Position::Prologue)
2129}
2130
2131/// Extracts a specific attribute value into a variable wrapped in Option type.
2132///
2133/// This attribute macro retrieves a specific attribute by key and makes it available
2134/// as a typed Option variable from the request context. The extracted value is wrapped
2135/// in an Option type to safely handle cases where the attribute may not exist.
2136///
2137/// # Usage
2138///
2139/// ```rust
2140/// use hyperlane::*;
2141/// use hyperlane_macros::*;
2142/// use serde::{Deserialize, Serialize};
2143///
2144/// const TEST_ATTRIBUTE_KEY: &str = "test_attribute_key";
2145///
2146/// #[derive(Debug, Serialize, Deserialize, Clone)]
2147/// struct TestData {
2148///     name: String,
2149///     age: u32,
2150/// }
2151///
2152/// #[route("/attribute_option")]
2153/// struct Attribute;
2154///
2155/// impl ServerHook for Attribute {
2156///     async fn new(_ctx: &Context) -> Self {
2157///         Self
2158///     }
2159///
2160///     #[response_body(&format!("request attribute: {request_attribute_option:?}"))]
2161///     #[attribute_option(TEST_ATTRIBUTE_KEY => request_attribute_option: TestData)]
2162///     async fn handle(self, ctx: &Context) {}
2163/// }
2164///
2165/// impl Attribute {
2166///     #[attribute_option(TEST_ATTRIBUTE_KEY => request_attribute_option: TestData)]
2167///     async fn attribute_with_ref_self(&self, ctx: &Context) {}
2168/// }
2169///
2170/// #[attribute_option(TEST_ATTRIBUTE_KEY => request_attribute_option: TestData)]
2171/// async fn standalone_attribute_handler(ctx: &Context) {}
2172/// ```
2173///
2174/// The macro accepts a key-to-variable mapping in the format `key => variable_name: Type`.
2175/// The variable will be available as an `Option<Type>` in the function scope.
2176///
2177/// # Multi-Parameter Usage
2178///
2179/// ```rust
2180/// use hyperlane::*;
2181/// use hyperlane_macros::*;
2182///
2183/// #[route("/attribute_option")]
2184/// struct MultiAttr;
2185///
2186/// impl ServerHook for MultiAttr {
2187///     async fn new(_ctx: &Context) -> Self {
2188///         Self
2189///     }
2190///
2191///     #[response_body(&format!("attrs: {attr1:?}, {attr2:?}"))]
2192///     #[attribute_option("key1" => attr1: String, "key2" => attr2: i32)]
2193///     async fn handle(self, ctx: &Context) {}
2194/// }
2195/// ```
2196///
2197/// The macro accepts multiple `key => variable_name: Type` tuples separated by commas.
2198#[proc_macro_attribute]
2199pub fn attribute_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2200    attribute_option_macro(attr, item, Position::Prologue)
2201}
2202
2203/// Extracts a specific attribute value into a variable with panic on missing value.
2204///
2205/// This attribute macro retrieves a specific attribute by key and makes it available
2206/// as a typed variable from the request context. If the attribute does not exist,
2207/// the function will panic with an error message indicating the missing attribute.
2208///
2209/// # Usage
2210///
2211/// ```rust
2212/// use hyperlane::*;
2213/// use hyperlane_macros::*;
2214/// use serde::{Deserialize, Serialize};
2215///
2216/// const TEST_ATTRIBUTE_KEY: &str = "test_attribute_key";
2217///
2218/// #[derive(Debug, Serialize, Deserialize, Clone)]
2219/// struct TestData {
2220///     name: String,
2221///     age: u32,
2222/// }
2223///
2224/// #[route("/attribute")]
2225/// struct Attribute;
2226///
2227/// impl ServerHook for Attribute {
2228///     async fn new(_ctx: &Context) -> Self {
2229///         Self
2230///     }
2231///
2232///     #[response_body(&format!("request attribute: {request_attribute:?}"))]
2233///     #[attribute(TEST_ATTRIBUTE_KEY => request_attribute: TestData)]
2234///     async fn handle(self, ctx: &Context) {}
2235/// }
2236///
2237/// impl Attribute {
2238///     #[attribute(TEST_ATTRIBUTE_KEY => request_attribute: TestData)]
2239///     async fn attribute_with_ref_self(&self, ctx: &Context) {}
2240/// }
2241///
2242/// #[attribute(TEST_ATTRIBUTE_KEY => request_attribute: TestData)]
2243/// async fn standalone_attribute_handler(ctx: &Context) {}
2244/// ```
2245///
2246/// The macro accepts a key-to-variable mapping in the format `key => variable_name: Type`.
2247/// The variable will be available as an `Type` in the function scope.
2248///
2249/// # Multi-Parameter Usage
2250///
2251/// ```rust
2252/// use hyperlane::*;
2253/// use hyperlane_macros::*;
2254///
2255/// #[route("/attribute")]
2256/// struct MultiAttr;
2257///
2258/// impl ServerHook for MultiAttr {
2259///     async fn new(_ctx: &Context) -> Self {
2260///         Self
2261///     }
2262///
2263///     #[response_body(&format!("attrs: {attr1}, {attr2}"))]
2264///     #[attribute("key1" => attr1: String, "key2" => attr2: i32)]
2265///     async fn handle(self, ctx: &Context) {}
2266/// }
2267/// ```
2268///
2269/// The macro accepts multiple `key => variable_name: Type` tuples separated by commas.
2270///
2271/// # Panics
2272///
2273/// This macro will panic if the requested attribute does not exist in the request context.
2274#[proc_macro_attribute]
2275pub fn attribute(attr: TokenStream, item: TokenStream) -> TokenStream {
2276    attribute_macro(attr, item, Position::Prologue)
2277}
2278
2279/// Extracts all attributes into a ThreadSafeAttributeStore variable.
2280///
2281/// This attribute macro retrieves all available attributes from the request context
2282/// and makes them available as a ThreadSafeAttributeStore for comprehensive attribute access.
2283///
2284/// # Usage
2285///
2286/// ```rust
2287/// use hyperlane::*;
2288/// use hyperlane_macros::*;
2289///
2290/// #[route("/attributes")]
2291/// struct Attributes;
2292///
2293/// impl ServerHook for Attributes {
2294///     async fn new(_ctx: &Context) -> Self {
2295///         Self
2296///     }
2297///
2298///     #[response_body(&format!("request attributes: {request_attributes:?}"))]
2299///     #[attributes(request_attributes)]
2300///     async fn handle(self, ctx: &Context) {}
2301/// }
2302///
2303/// impl Attributes {
2304///     #[attributes(request_attributes)]
2305///     async fn attributes_with_ref_self(&self, ctx: &Context) {}
2306/// }
2307///
2308/// #[attributes(request_attributes)]
2309/// async fn standalone_attributes_handler(ctx: &Context) {}
2310/// ```
2311///
2312/// The macro accepts a variable name that will contain a HashMap of all attributes.
2313/// The variable will be available as a HashMap in the function scope.
2314///
2315/// # Multi-Parameter Usage
2316///
2317/// ```rust
2318/// use hyperlane::*;
2319/// use hyperlane_macros::*;
2320///
2321/// #[route("/multi_attrs")]
2322/// struct MultiAttrs;
2323///
2324/// impl ServerHook for MultiAttrs {
2325///     async fn new(_ctx: &Context) -> Self {
2326///         Self
2327///     }
2328///
2329///     #[response_body(&format!("attrs1: {attrs1:?}, attrs2: {attrs2:?}"))]
2330///     #[attributes(attrs1, attrs2)]
2331///     async fn handle(self, ctx: &Context) {}
2332/// }
2333/// ```
2334///
2335/// The macro accepts multiple variable names separated by commas.
2336#[proc_macro_attribute]
2337pub fn attributes(attr: TokenStream, item: TokenStream) -> TokenStream {
2338    attributes_macro(attr, item, Position::Prologue)
2339}
2340
2341/// Extracts panic data into a variable wrapped in Option type.
2342///
2343/// This attribute macro retrieves panic information if a panic occurred during handling
2344/// and makes it available as an Option variable. The extracted value is wrapped
2345/// in an Option type to safely handle cases where no panic occurred.
2346///
2347/// # Usage
2348///
2349/// ```rust
2350/// use hyperlane::*;
2351/// use hyperlane_macros::*;
2352///
2353/// #[route("/task_panic_data_option")]
2354/// struct PanicDataOptionTest;
2355///
2356/// impl ServerHook for PanicDataOptionTest {
2357///     async fn new(_ctx: &Context) -> Self {
2358///         Self
2359///     }
2360///
2361///     #[response_body(&format!("Panic data: {task_panic_data_option:?}"))]
2362///     #[task_panic_data_option(task_panic_data_option)]
2363///     async fn handle(self, ctx: &Context) {}
2364/// }
2365///
2366/// impl PanicDataOptionTest {
2367///     #[task_panic_data_option(task_panic_data_option)]
2368///     async fn task_panic_data_option_with_ref_self(&self, ctx: &Context) {}
2369/// }
2370///
2371/// #[task_panic_data_option(task_panic_data_option)]
2372/// async fn standalone_task_panic_data_option_handler(ctx: &Context) {}
2373/// ```
2374///
2375/// The macro accepts a variable name that will contain the panic data.
2376/// The variable will be available as an `Option<PanicData>` in the function scope.
2377///
2378/// # Multi-Parameter Usage
2379///
2380/// ```rust
2381/// use hyperlane::*;
2382/// use hyperlane_macros::*;
2383///
2384/// #[route("/task_panic_data_option")]
2385/// struct MultiPanicDataOption;
2386///
2387/// impl ServerHook for MultiPanicDataOption {
2388///     async fn new(_ctx: &Context) -> Self {
2389///         Self
2390///     }
2391///
2392///     #[response_body(&format!("panic1: {panic1:?}, panic2: {panic2:?}"))]
2393///     #[task_panic_data_option(panic1, panic2)]
2394///     async fn handle(self, ctx: &Context) {}
2395/// }
2396/// ```
2397///
2398/// The macro accepts multiple variable names separated by commas.
2399#[proc_macro_attribute]
2400pub fn task_panic_data_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2401    task_panic_data_option_macro(attr, item, Position::Prologue)
2402}
2403
2404/// Extracts panic data into a variable with panic on missing value.
2405///
2406/// This attribute macro retrieves panic information if a panic occurred during handling
2407/// and makes it available as a variable. If no panic data exists,
2408/// the function will panic with an error message.
2409///
2410/// # Usage
2411///
2412/// ```rust
2413/// use hyperlane::*;
2414/// use hyperlane_macros::*;
2415///
2416/// #[route("/task_panic_data")]
2417/// struct PanicDataTest;
2418///
2419/// impl ServerHook for PanicDataTest {
2420///     async fn new(_ctx: &Context) -> Self {
2421///         Self
2422///     }
2423///
2424///     #[response_body(&format!("Panic data: {task_panic_data}"))]
2425///     #[task_panic_data(task_panic_data)]
2426///     async fn handle(self, ctx: &Context) {}
2427/// }
2428///
2429/// impl PanicDataTest {
2430///     #[task_panic_data(task_panic_data)]
2431///     async fn task_panic_data_with_ref_self(&self, ctx: &Context) {}
2432/// }
2433///
2434/// #[task_panic_data(task_panic_data)]
2435/// async fn standalone_task_panic_data_handler(ctx: &Context) {}
2436/// ```
2437///
2438/// The macro accepts a variable name that will contain the panic data.
2439/// The variable will be available as a `PanicData` in the function scope.
2440///
2441/// # Multi-Parameter Usage
2442///
2443/// ```rust
2444/// use hyperlane::*;
2445/// use hyperlane_macros::*;
2446///
2447/// #[route("/task_panic_data")]
2448/// struct MultiPanicData;
2449///
2450/// impl ServerHook for MultiPanicData {
2451///     async fn new(_ctx: &Context) -> Self {
2452///         Self
2453///     }
2454///
2455///     #[response_body(&format!("panic1: {panic1}, panic2: {panic2}"))]
2456///     #[task_panic_data(panic1, panic2)]
2457///     async fn handle(self, ctx: &Context) {}
2458/// }
2459/// ```
2460///
2461/// The macro accepts multiple variable names separated by commas.
2462///
2463/// # Panics
2464///
2465/// This macro will panic if no panic data exists in the request context.
2466#[proc_macro_attribute]
2467pub fn task_panic_data(attr: TokenStream, item: TokenStream) -> TokenStream {
2468    task_panic_data_macro(attr, item, Position::Prologue)
2469}
2470
2471/// Extracts request error data into a variable wrapped in Option type.
2472///
2473/// This attribute macro retrieves request error information if an error occurred during handling
2474/// and makes it available as an Option variable. The extracted value is wrapped
2475/// in an Option type to safely handle cases where no error occurred.
2476///
2477/// # Usage
2478///
2479/// ```rust
2480/// use hyperlane::*;
2481/// use hyperlane_macros::*;
2482///
2483/// #[route("/request_error_data_option")]
2484/// struct RequestErrorDataOptionTest;
2485///
2486/// impl ServerHook for RequestErrorDataOptionTest {
2487///     async fn new(_ctx: &Context) -> Self {
2488///         Self
2489///     }
2490///
2491///     #[response_body(&format!("Request error data: {request_error_data_option:?}"))]
2492///     #[request_error_data_option(request_error_data_option)]
2493///     async fn handle(self, ctx: &Context) {}
2494/// }
2495///
2496/// impl RequestErrorDataOptionTest {
2497///     #[request_error_data_option(request_error_data_option)]
2498///     async fn request_error_data_option_with_ref_self(&self, ctx: &Context) {}
2499/// }
2500///
2501/// #[request_error_data_option(request_error_data_option)]
2502/// async fn standalone_request_error_data_option_handler(ctx: &Context) {}
2503/// ```
2504///
2505/// The macro accepts a variable name that will contain the request error data.
2506/// The variable will be available as an `Option<RequestError>` in the function scope.
2507///
2508/// # Multi-Parameter Usage
2509///
2510/// ```rust
2511/// use hyperlane::*;
2512/// use hyperlane_macros::*;
2513///
2514/// #[route("/request_error_data_option")]
2515/// struct MultiRequestErrorDataOption;
2516///
2517/// impl ServerHook for MultiRequestErrorDataOption {
2518///     async fn new(_ctx: &Context) -> Self {
2519///         Self
2520///     }
2521///
2522///     #[response_body(&format!("error1: {error1:?}, error2: {error2:?}"))]
2523///     #[request_error_data_option(error1, error2)]
2524///     async fn handle(self, ctx: &Context) {}
2525/// }
2526/// ```
2527///
2528/// The macro accepts multiple variable names separated by commas.
2529#[proc_macro_attribute]
2530pub fn request_error_data_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2531    request_error_data_option_macro(attr, item, Position::Prologue)
2532}
2533
2534/// Extracts request error data into a variable with panic on missing value.
2535///
2536/// This attribute macro retrieves request error information if an error occurred during handling
2537/// and makes it available as a variable. If no error data exists,
2538/// the function will panic with an error message.
2539///
2540/// # Usage
2541///
2542/// ```rust
2543/// use hyperlane::*;
2544/// use hyperlane_macros::*;
2545///
2546/// #[route("/request_error_data")]
2547/// struct RequestErrorDataTest;
2548///
2549/// impl ServerHook for RequestErrorDataTest {
2550///     async fn new(_ctx: &Context) -> Self {
2551///         Self
2552///     }
2553///
2554///     #[response_body(&format!("Request error data: {request_error_data}"))]
2555///     #[request_error_data(request_error_data)]
2556///     async fn handle(self, ctx: &Context) {}
2557/// }
2558///
2559/// impl RequestErrorDataTest {
2560///     #[request_error_data(request_error_data)]
2561///     async fn request_error_data_with_ref_self(&self, ctx: &Context) {}
2562/// }
2563///
2564/// #[request_error_data(request_error_data)]
2565/// async fn standalone_request_error_data_handler(ctx: &Context) {}
2566/// ```
2567///
2568/// The macro accepts a variable name that will contain the request error data.
2569/// The variable will be available as a `RequestError` in the function scope.
2570///
2571/// # Multi-Parameter Usage
2572///
2573/// ```rust
2574/// use hyperlane::*;
2575/// use hyperlane_macros::*;
2576///
2577/// #[route("/request_error_data")]
2578/// struct MultiRequestErrorData;
2579///
2580/// impl ServerHook for MultiRequestErrorData {
2581///     async fn new(_ctx: &Context) -> Self {
2582///         Self
2583///     }
2584///
2585///     #[response_body(&format!("error1: {error1}, error2: {error2}"))]
2586///     #[request_error_data(error1, error2)]
2587///     async fn handle(self, ctx: &Context) {}
2588/// }
2589/// ```
2590///
2591/// The macro accepts multiple variable names separated by commas.
2592///
2593/// # Panics
2594///
2595/// This macro will panic if no request error data exists in the request context.
2596#[proc_macro_attribute]
2597pub fn request_error_data(attr: TokenStream, item: TokenStream) -> TokenStream {
2598    request_error_data_macro(attr, item, Position::Prologue)
2599}
2600
2601/// Extracts a specific route parameter into a variable wrapped in Option type.
2602///
2603/// This attribute macro retrieves a specific route parameter by key and makes it
2604/// available as an Option variable. Route parameters are extracted from the URL path segments
2605/// and wrapped in an Option type to safely handle cases where the parameter may not exist.
2606///
2607/// # Usage
2608///
2609/// ```rust
2610/// use hyperlane::*;
2611/// use hyperlane_macros::*;
2612///
2613/// #[route("/route_param_option/:test")]
2614/// struct RouteParam;
2615///
2616/// impl ServerHook for RouteParam {
2617///     async fn new(_ctx: &Context) -> Self {
2618///         Self
2619///     }
2620///
2621///     #[response_body(&format!("route param: {request_route_param:?}"))]
2622///     #[route_param_option("test" => request_route_param)]
2623///     async fn handle(self, ctx: &Context) {}
2624/// }
2625///
2626/// impl RouteParam {
2627///     #[route_param_option("test" => request_route_param)]
2628///     async fn route_param_with_ref_self(&self, ctx: &Context) {}
2629/// }
2630///
2631/// #[route_param_option("test" => request_route_param)]
2632/// async fn standalone_route_param_handler(ctx: &Context) {}
2633/// ```
2634///
2635/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2636/// The variable will be available as an `Option<String>` in the function scope.
2637///
2638/// # Multi-Parameter Usage
2639///
2640/// ```rust
2641/// use hyperlane::*;
2642/// use hyperlane_macros::*;
2643///
2644/// #[route("/multi_param/:id/:name")]
2645/// struct MultiParam;
2646///
2647/// impl ServerHook for MultiParam {
2648///     async fn new(_ctx: &Context) -> Self {
2649///         Self
2650///     }
2651///
2652///     #[response_body(&format!("id: {id:?}, name: {name:?}"))]
2653///     #[route_param_option("id" => id, "name" => name)]
2654///     async fn handle(self, ctx: &Context) {}
2655/// }
2656/// ```
2657///
2658/// The macro accepts multiple `"key" => variable_name` pairs separated by commas.
2659#[proc_macro_attribute]
2660pub fn route_param_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2661    route_param_option_macro(attr, item, Position::Prologue)
2662}
2663
2664/// Extracts a specific route parameter into a variable with panic on missing value.
2665///
2666/// This attribute macro retrieves a specific route parameter by key and makes it
2667/// available as a variable. Route parameters are extracted from the URL path segments.
2668/// If the requested route parameter does not exist, the function will panic with an error message.
2669///
2670/// # Usage
2671///
2672/// ```rust
2673/// use hyperlane::*;
2674/// use hyperlane_macros::*;
2675///
2676/// #[route("/route_param/:test")]
2677/// struct RouteParam;
2678///
2679/// impl ServerHook for RouteParam {
2680///     async fn new(_ctx: &Context) -> Self {
2681///         Self
2682///     }
2683///
2684///     #[response_body(&format!("route param: {request_route_param:?}"))]
2685///     #[route_param("test" => request_route_param)]
2686///     async fn handle(self, ctx: &Context) {}
2687/// }
2688///
2689/// impl RouteParam {
2690///     #[route_param("test" => request_route_param)]
2691///     async fn route_param_with_ref_self(&self, ctx: &Context) {}
2692/// }
2693///
2694/// #[route_param("test" => request_route_param)]
2695/// async fn standalone_route_param_handler(ctx: &Context) {}
2696/// ```
2697///
2698/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2699/// The variable will be available as an `String` in the function scope.
2700///
2701///
2702/// # Multi-Parameter Usage
2703///
2704/// ```rust
2705/// use hyperlane::*;
2706/// use hyperlane_macros::*;
2707///
2708/// #[route("/multi_param/:id/:name")]
2709/// struct MultiParam;
2710///
2711/// impl ServerHook for MultiParam {
2712///     async fn new(_ctx: &Context) -> Self {
2713///         Self
2714///     }
2715///
2716///     #[response_body(&format!("id: {id:?}, name: {name:?}"))]
2717///     #[route_param("id" => id, "name" => name)]
2718///     async fn handle(self, ctx: &Context) {}
2719/// }
2720/// ```
2721///
2722/// The macro accepts multiple `"key" => variable_name` pairs separated by commas.
2723///
2724/// # Panics
2725///
2726/// This macro will panic if the requested route parameter does not exist in the URL path.
2727#[proc_macro_attribute]
2728pub fn route_param(attr: TokenStream, item: TokenStream) -> TokenStream {
2729    route_param_macro(attr, item, Position::Prologue)
2730}
2731
2732/// Extracts all route parameters into a collection variable.
2733///
2734/// This attribute macro retrieves all available route parameters from the URL path
2735/// and makes them available as a collection for comprehensive route parameter access.
2736///
2737/// # Usage
2738///
2739/// ```rust
2740/// use hyperlane::*;
2741/// use hyperlane_macros::*;
2742///
2743/// #[route("/route_params/:test")]
2744/// struct RouteParams;
2745///
2746/// impl ServerHook for RouteParams {
2747///     async fn new(_ctx: &Context) -> Self {
2748///         Self
2749///     }
2750///
2751///     #[response_body(&format!("request route params: {request_route_params:?}"))]
2752///     #[route_params(request_route_params)]
2753///     async fn handle(self, ctx: &Context) {}
2754/// }
2755///
2756/// impl RouteParams {
2757///     #[route_params(request_route_params)]
2758///     async fn route_params_with_ref_self(&self, ctx: &Context) {}
2759/// }
2760///
2761/// #[route_params(request_route_params)]
2762/// async fn standalone_route_params_handler(ctx: &Context) {}
2763/// ```
2764///
2765/// The macro accepts a variable name that will contain all route parameters.
2766/// The variable will be available as a RouteParams type in the function scope.
2767///
2768/// # Multi-Parameter Usage
2769///
2770/// ```rust
2771/// use hyperlane::*;
2772/// use hyperlane_macros::*;
2773///
2774/// #[route("/multi_params/:id")]
2775/// struct MultiParams;
2776///
2777/// impl ServerHook for MultiParams {
2778///     async fn new(_ctx: &Context) -> Self {
2779///         Self
2780///     }
2781///
2782///     #[response_body(&format!("params1: {params1:?}, params2: {params2:?}"))]
2783///     #[route_params(params1, params2)]
2784///     async fn handle(self, ctx: &Context) {}
2785/// }
2786/// ```
2787///
2788/// The macro accepts multiple variable names separated by commas.
2789#[proc_macro_attribute]
2790pub fn route_params(attr: TokenStream, item: TokenStream) -> TokenStream {
2791    route_params_macro(attr, item, Position::Prologue)
2792}
2793
2794/// Extracts a specific request query parameter into a variable wrapped in Option type.
2795///
2796/// This attribute macro retrieves a specific request query parameter by key and makes it
2797/// available as an Option variable. Query parameters are extracted from the URL request query string
2798/// and wrapped in an Option type to safely handle cases where the parameter may not exist.
2799///
2800/// # Usage
2801///
2802/// ```rust
2803/// use hyperlane::*;
2804/// use hyperlane_macros::*;
2805///
2806/// #[route("/request_query_option")]
2807/// struct RequestQuery;
2808///
2809/// impl ServerHook for RequestQuery {
2810///     async fn new(_ctx: &Context) -> Self {
2811///         Self
2812///     }
2813///
2814///     #[prologue_macros(
2815///         request_query_option("test" => request_query_option),
2816///         response_body(&format!("request query: {request_query_option:?}")),
2817///         send
2818///     )]
2819///     async fn handle(self, ctx: &Context) {}
2820/// }
2821///
2822/// impl RequestQuery {
2823///     #[request_query_option("test" => request_query_option)]
2824///     async fn request_query_with_ref_self(&self, ctx: &Context) {}
2825/// }
2826///
2827/// #[request_query_option("test" => request_query_option)]
2828/// async fn standalone_request_query_handler(ctx: &Context) {}
2829/// ```
2830///
2831/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2832/// The variable will be available as an `Option<RequestQuerysValue>` in the function scope.
2833///
2834/// Supports multiple parameters: `#[request_query_option("k1" => v1, "k2" => v2)]`
2835#[proc_macro_attribute]
2836pub fn request_query_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2837    request_query_option_macro(attr, item, Position::Prologue)
2838}
2839
2840/// Extracts a specific request query parameter into a variable with panic on missing value.
2841///
2842/// This attribute macro retrieves a specific request query parameter by key and makes it
2843/// available as a variable. Query parameters are extracted from the URL request query string.
2844/// If the requested query parameter does not exist, the function will panic with an error message.
2845///
2846/// # Usage
2847///
2848/// ```rust
2849/// use hyperlane::*;
2850/// use hyperlane_macros::*;
2851///
2852/// #[route("/request_query")]
2853/// struct RequestQuery;
2854///
2855/// impl ServerHook for RequestQuery {
2856///     async fn new(_ctx: &Context) -> Self {
2857///         Self
2858///     }
2859///
2860///     #[prologue_macros(
2861///         request_query("test" => request_query),
2862///         response_body(&format!("request query: {request_query}")),
2863///         send
2864///     )]
2865///     async fn handle(self, ctx: &Context) {}
2866/// }
2867///
2868/// impl RequestQuery {
2869///     #[request_query("test" => request_query)]
2870///     async fn request_query_with_ref_self(&self, ctx: &Context) {}
2871/// }
2872///
2873/// #[request_query("test" => request_query)]
2874/// async fn standalone_request_query_handler(ctx: &Context) {}
2875/// ```
2876///
2877/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2878/// The variable will be available as an `RequestQuerysValue` in the function scope.
2879///
2880/// Supports multiple parameters: `#[request_query("k1" => v1, "k2" => v2)]`
2881///
2882/// # Panics
2883///
2884/// This macro will panic if the requested query parameter does not exist in the URL query string.
2885#[proc_macro_attribute]
2886pub fn request_query(attr: TokenStream, item: TokenStream) -> TokenStream {
2887    request_query_macro(attr, item, Position::Prologue)
2888}
2889
2890/// Extracts all request query parameters into a RequestQuerys variable.
2891///
2892/// This attribute macro retrieves all available request query parameters from the URL request query string
2893/// and makes them available as a RequestQuerys for comprehensive request query parameter access.
2894///
2895/// # Usage
2896///
2897/// ```rust
2898/// use hyperlane::*;
2899/// use hyperlane_macros::*;
2900///
2901/// #[route("/request_querys")]
2902/// struct RequestQuerys;
2903///
2904/// impl ServerHook for RequestQuerys {
2905///     async fn new(_ctx: &Context) -> Self {
2906///         Self
2907///     }
2908///
2909///     #[prologue_macros(
2910///         request_querys(request_querys),
2911///         response_body(&format!("request querys: {request_querys:?}")),
2912///         send
2913///     )]
2914///     async fn handle(self, ctx: &Context) {}
2915/// }
2916///
2917/// impl RequestQuerys {
2918///     #[request_querys(request_querys)]
2919///     async fn request_querys_with_ref_self(&self, ctx: &Context) {}
2920/// }
2921///
2922/// #[request_querys(request_querys)]
2923/// async fn standalone_request_querys_handler(ctx: &Context) {}
2924/// ```
2925///
2926/// The macro accepts a variable name that will contain all request query parameters.
2927/// The variable will be available as a collection in the function scope.
2928///
2929/// Supports multiple parameters: `#[request_querys(querys1, querys2)]`
2930#[proc_macro_attribute]
2931pub fn request_querys(attr: TokenStream, item: TokenStream) -> TokenStream {
2932    request_querys_macro(attr, item, Position::Prologue)
2933}
2934
2935/// Extracts a specific HTTP request header into a variable wrapped in Option type.
2936///
2937/// This attribute macro retrieves a specific HTTP request header by name and makes it
2938/// available as an Option variable. Header values are extracted from the request request headers collection
2939/// and wrapped in an Option type to safely handle cases where the header may not exist.
2940///
2941/// # Usage
2942///
2943/// ```rust
2944/// use hyperlane::*;
2945/// use hyperlane_macros::*;
2946///
2947/// #[route("/request_header_option")]
2948/// struct RequestHeader;
2949///
2950/// impl ServerHook for RequestHeader {
2951///     async fn new(_ctx: &Context) -> Self {
2952///         Self
2953///     }
2954///
2955///     #[prologue_macros(
2956///         request_header_option(HOST => request_header_option),
2957///         response_body(&format!("request header: {request_header_option:?}")),
2958///         send
2959///     )]
2960///     async fn handle(self, ctx: &Context) {}
2961/// }
2962///
2963/// impl RequestHeader {
2964///     #[request_header_option(HOST => request_header_option)]
2965///     async fn request_header_with_ref_self(&self, ctx: &Context) {}
2966/// }
2967///
2968/// #[request_header_option(HOST => request_header_option)]
2969/// async fn standalone_request_header_handler(ctx: &Context) {}
2970/// ```
2971///
2972/// The macro accepts a request header name-to-variable mapping in the format `HEADER_NAME => variable_name`
2973/// or `"Header-Name" => variable_name`. The variable will be available as an `Option<RequestHeadersValueItem>`.
2974#[proc_macro_attribute]
2975pub fn request_header_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2976    request_header_option_macro(attr, item, Position::Prologue)
2977}
2978
2979/// Extracts a specific HTTP request header into a variable with panic on missing value.
2980///
2981/// This attribute macro retrieves a specific HTTP request header by name and makes it
2982/// available as a variable. Header values are extracted from the request request headers collection.
2983/// If the requested header does not exist, the function will panic with an error message.
2984///
2985/// # Usage
2986///
2987/// ```rust
2988/// use hyperlane::*;
2989/// use hyperlane_macros::*;
2990///
2991/// #[route("/request_header")]
2992/// struct RequestHeader;
2993///
2994/// impl ServerHook for RequestHeader {
2995///     async fn new(_ctx: &Context) -> Self {
2996///         Self
2997///     }
2998///
2999///     #[prologue_macros(
3000///         request_header(HOST => request_header),
3001///         response_body(&format!("request header: {request_header}")),
3002///         send
3003///     )]
3004///     async fn handle(self, ctx: &Context) {}
3005/// }
3006///
3007/// impl RequestHeader {
3008///     #[request_header(HOST => request_header)]
3009///     async fn request_header_with_ref_self(&self, ctx: &Context) {}
3010/// }
3011///
3012/// #[request_header(HOST => request_header)]
3013/// async fn standalone_request_header_handler(ctx: &Context) {}
3014/// ```
3015///
3016/// The macro accepts a request header name-to-variable mapping in the format `HEADER_NAME => variable_name`
3017/// or `"Header-Name" => variable_name`. The variable will be available as an `RequestHeadersValueItem`.
3018///
3019/// # Panics
3020///
3021/// This macro will panic if the requested header does not exist in the HTTP request headers.
3022#[proc_macro_attribute]
3023pub fn request_header(attr: TokenStream, item: TokenStream) -> TokenStream {
3024    request_header_macro(attr, item, Position::Prologue)
3025}
3026
3027/// Extracts all HTTP request headers into a collection variable.
3028///
3029/// This attribute macro retrieves all available HTTP request headers from the request
3030/// and makes them available as a collection for comprehensive request header access.
3031///
3032/// # Usage
3033///
3034/// ```rust
3035/// use hyperlane::*;
3036/// use hyperlane_macros::*;
3037///
3038/// #[route("/request_headers")]
3039/// struct RequestHeaders;
3040///
3041/// impl ServerHook for RequestHeaders {
3042///     async fn new(_ctx: &Context) -> Self {
3043///         Self
3044///     }
3045///
3046///     #[prologue_macros(
3047///         request_headers(request_headers),
3048///         response_body(&format!("request headers: {request_headers:?}")),
3049///         send
3050///     )]
3051///     async fn handle(self, ctx: &Context) {}
3052/// }
3053///
3054/// impl RequestHeaders {
3055///     #[request_headers(request_headers)]
3056///     async fn request_headers_with_ref_self(&self, ctx: &Context) {}
3057/// }
3058///
3059/// #[request_headers(request_headers)]
3060/// async fn standalone_request_headers_handler(ctx: &Context) {}
3061/// ```
3062///
3063/// The macro accepts a variable name that will contain all HTTP request headers.
3064/// The variable will be available as a RequestHeaders type in the function scope.
3065#[proc_macro_attribute]
3066pub fn request_headers(attr: TokenStream, item: TokenStream) -> TokenStream {
3067    request_headers_macro(attr, item, Position::Prologue)
3068}
3069
3070/// Extracts a specific cookie value or all cookies into a variable wrapped in Option type.
3071///
3072/// This attribute macro supports two syntaxes:
3073/// 1. `cookie(key => variable_name)` - Extract a specific cookie value by key, wrapped in Option
3074/// 2. `cookie(variable_name)` - Extract all cookies as a raw string, wrapped in Option
3075///
3076/// # Usage
3077///
3078/// ```rust
3079/// use hyperlane::*;
3080/// use hyperlane_macros::*;
3081///
3082/// #[route("/cookie")]
3083/// struct Cookie;
3084///
3085/// impl ServerHook for Cookie {
3086///     async fn new(_ctx: &Context) -> Self {
3087///         Self
3088///     }
3089///
3090///     #[response_body(&format!("Session cookie: {session_cookie1_option:?}, {session_cookie2_option:?}"))]
3091///     #[request_cookie_option("test1" => session_cookie1_option, "test2" => session_cookie2_option)]
3092///     async fn handle(self, ctx: &Context) {}
3093/// }
3094///
3095/// impl Cookie {
3096///     #[response_body(&format!("Session cookie: {session_cookie1_option:?}, {session_cookie2_option:?}"))]
3097///     #[request_cookie_option("test1" => session_cookie1_option, "test2" => session_cookie2_option)]
3098///     async fn request_cookie_with_ref_self(&self, ctx: &Context) {}
3099/// }
3100///
3101/// #[response_body(&format!("Session cookie: {session_cookie1_option:?}, {session_cookie2_option:?}"))]
3102/// #[request_cookie_option("test1" => session_cookie1_option, "test2" => session_cookie2_option)]
3103/// async fn standalone_request_cookie_handler(ctx: &Context) {}
3104/// ```
3105///
3106/// For specific cookie extraction, the variable will be available as `Option<String>`.
3107/// For all cookies extraction, the variable will be available as `String`.
3108#[proc_macro_attribute]
3109pub fn request_cookie_option(attr: TokenStream, item: TokenStream) -> TokenStream {
3110    request_cookie_option_macro(attr, item, Position::Prologue)
3111}
3112
3113/// Extracts a specific cookie value or all cookies into a variable with panic on missing value.
3114///
3115/// This attribute macro supports two syntaxes:
3116/// 1. `cookie(key => variable_name)` - Extract a specific cookie value by key, panics if missing
3117/// 2. `cookie(variable_name)` - Extract all cookies as a raw string, panics if missing
3118///
3119/// # Usage
3120///
3121/// ```rust
3122/// use hyperlane::*;
3123/// use hyperlane_macros::*;
3124///
3125/// #[route("/cookie")]
3126/// struct Cookie;
3127///
3128/// impl ServerHook for Cookie {
3129///     async fn new(_ctx: &Context) -> Self {
3130///         Self
3131///     }
3132///
3133///     #[response_body(&format!("Session cookie: {session_cookie1}, {session_cookie2}"))]
3134///     #[request_cookie("test1" => session_cookie1, "test2" => session_cookie2)]
3135///     async fn handle(self, ctx: &Context) {}
3136/// }
3137///
3138/// impl Cookie {
3139///     #[response_body(&format!("Session cookie: {session_cookie1}, {session_cookie2}"))]
3140///     #[request_cookie("test1" => session_cookie1, "test2" => session_cookie2)]
3141///     async fn request_cookie_with_ref_self(&self, ctx: &Context) {}
3142/// }
3143///
3144/// #[response_body(&format!("Session cookie: {session_cookie1}, {session_cookie2}"))]
3145/// #[request_cookie("test1" => session_cookie1, "test2" => session_cookie2)]
3146/// async fn standalone_request_cookie_handler(ctx: &Context) {}
3147/// ```
3148///
3149/// For specific cookie extraction, the variable will be available as `String`.
3150/// For all cookies extraction, the variable will be available as `String`.
3151///
3152/// # Panics
3153///
3154/// This macro will panic if the requested cookie does not exist in the HTTP request headers.
3155#[proc_macro_attribute]
3156pub fn request_cookie(attr: TokenStream, item: TokenStream) -> TokenStream {
3157    request_cookie_macro(attr, item, Position::Prologue)
3158}
3159
3160/// Extracts all cookies as a raw string into a variable.
3161///
3162/// This attribute macro retrieves the entire Cookie header from the request and makes it
3163/// available as a String variable. If no Cookie header is present, an empty string is used.
3164///
3165/// # Usage
3166///
3167/// ```rust
3168/// use hyperlane::*;
3169/// use hyperlane_macros::*;
3170///
3171/// #[route("/cookies")]
3172/// struct Cookies;
3173///
3174/// impl ServerHook for Cookies {
3175///     async fn new(_ctx: &Context) -> Self {
3176///         Self
3177///     }
3178///
3179///     #[response_body(&format!("All cookies: {cookie_value:?}"))]
3180///     #[request_cookies(cookie_value)]
3181///     async fn handle(self, ctx: &Context) {}
3182/// }
3183///
3184/// impl Cookies {
3185///     #[request_cookies(cookie_value)]
3186///     async fn request_cookies_with_ref_self(&self, ctx: &Context) {}
3187/// }
3188///
3189/// #[request_cookies(cookie_value)]
3190/// async fn standalone_request_cookies_handler(ctx: &Context) {}
3191/// ```
3192///
3193/// The macro accepts a variable name that will contain all cookies.
3194/// The variable will be available as a Cookies type in the function scope.
3195#[proc_macro_attribute]
3196pub fn request_cookies(attr: TokenStream, item: TokenStream) -> TokenStream {
3197    request_cookies_macro(attr, item, Position::Prologue)
3198}
3199
3200/// Extracts the HTTP request version into a variable.
3201///
3202/// This attribute macro retrieves the HTTP version from the request and makes it
3203/// available as a variable. The version represents the HTTP protocol version used.
3204///
3205/// # Usage
3206///
3207/// ```rust
3208/// use hyperlane::*;
3209/// use hyperlane_macros::*;
3210///
3211/// #[route("/request_version")]
3212/// struct RequestVersionTest;
3213///
3214/// impl ServerHook for RequestVersionTest {
3215///     async fn new(_ctx: &Context) -> Self {
3216///         Self
3217///     }
3218///
3219///     #[response_body(&format!("HTTP Version: {http_version}"))]
3220///     #[request_version(http_version)]
3221///     async fn handle(self, ctx: &Context) {}
3222/// }
3223///
3224/// impl RequestVersionTest {
3225///     #[request_version(http_version)]
3226///     async fn request_version_with_ref_self(&self, ctx: &Context) {}
3227/// }
3228///
3229/// #[request_version(http_version)]
3230/// async fn standalone_request_version_handler(ctx: &Context) {}
3231/// ```
3232///
3233/// The macro accepts a variable name that will contain the HTTP request version.
3234/// The variable will be available as a RequestVersion type in the function scope.
3235#[proc_macro_attribute]
3236pub fn request_version(attr: TokenStream, item: TokenStream) -> TokenStream {
3237    request_version_macro(attr, item, Position::Prologue)
3238}
3239
3240/// Extracts the HTTP request path into a variable.
3241///
3242/// This attribute macro retrieves the request path from the HTTP request and makes it
3243/// available as a variable. The path represents the URL path portion of the request.
3244///
3245/// # Usage
3246///
3247/// ```rust
3248/// use hyperlane::*;
3249/// use hyperlane_macros::*;
3250///
3251/// #[route("/request_path")]
3252/// struct RequestPathTest;
3253///
3254/// impl ServerHook for RequestPathTest {
3255///     async fn new(_ctx: &Context) -> Self {
3256///         Self
3257///     }
3258///
3259///     #[response_body(&format!("Request Path: {request_path}"))]
3260///     #[request_path(request_path)]
3261///     async fn handle(self, ctx: &Context) {}
3262/// }
3263///
3264/// impl RequestPathTest {
3265///     #[request_path(request_path)]
3266///     async fn request_path_with_ref_self(&self, ctx: &Context) {}
3267/// }
3268///
3269/// #[request_path(request_path)]
3270/// async fn standalone_request_path_handler(ctx: &Context) {}
3271/// ```
3272///
3273/// The macro accepts a variable name that will contain the HTTP request path.
3274/// The variable will be available as a RequestPath type in the function scope.
3275#[proc_macro_attribute]
3276pub fn request_path(attr: TokenStream, item: TokenStream) -> TokenStream {
3277    request_path_macro(attr, item, Position::Prologue)
3278}
3279
3280/// Creates a new instance of a specified type with a given variable name.
3281///
3282/// This attribute macro generates an instance initialization at the beginning of the function.
3283///
3284/// # Usage
3285///
3286/// ```rust,no_run
3287/// use hyperlane::*;
3288/// use hyperlane_macros::*;
3289///
3290/// #[hyperlane(server: Server)]
3291/// #[hyperlane(server_config: ServerConfig)]
3292/// #[tokio::main]
3293/// async fn main() {
3294///     server_config.disable_nodelay().await;
3295///     server.server_config(server_config).await;
3296///     let server_hook: ServerControlHook = server.run().await.unwrap_or_default();
3297///     server_hook.wait().await;
3298/// }
3299/// ```
3300///
3301/// The macro accepts a `variable_name: Type` pair.
3302/// The variable will be available as an instance of the specified type in the function scope.
3303#[proc_macro_attribute]
3304pub fn hyperlane(attr: TokenStream, item: TokenStream) -> TokenStream {
3305    hyperlane_macro(attr, item)
3306}
3307
3308/// Registers a function as a route handler.
3309///
3310/// This attribute macro registers the decorated function as a route handler for a given path.
3311/// This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
3312///
3313/// # Usage
3314///
3315/// ```rust
3316/// use hyperlane::*;
3317/// use hyperlane_macros::*;
3318///
3319/// #[route("/response")]
3320/// struct Response;
3321///
3322/// impl ServerHook for Response {
3323///     async fn new(_ctx: &Context) -> Self {
3324///         Self
3325///     }
3326///
3327///     #[response_body("response")]
3328///     async fn handle(self, ctx: &Context) {}
3329/// }
3330/// ```
3331///
3332/// # Parameters
3333///
3334/// - `path`: String literal defining the route path
3335///
3336/// # Dependencies
3337///
3338/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
3339#[proc_macro_attribute]
3340pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream {
3341    route_macro(attr, item)
3342}
3343
3344/// Registers a function as a request middleware.
3345///
3346/// This attribute macro registers the decorated function to be executed as a middleware
3347/// for incoming requests. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
3348///
3349/// # Note
3350///
3351/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
3352///
3353/// # Usage
3354///
3355/// ```rust
3356/// use hyperlane::*;
3357/// use hyperlane_macros::*;
3358///
3359/// #[request_middleware]
3360/// struct RequestMiddleware;
3361///
3362/// impl ServerHook for RequestMiddleware {
3363///     async fn new(_ctx: &Context) -> Self {
3364///         Self
3365///     }
3366///
3367///     #[epilogue_macros(
3368///         response_status_code(200),
3369///         response_version(HttpVersion::Http1_1),
3370///         response_header(SERVER => HYPERLANE)
3371///     )]
3372///     async fn handle(self, ctx: &Context) {}
3373/// }
3374/// ```
3375///
3376/// # Dependencies
3377///
3378/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
3379#[proc_macro_attribute]
3380pub fn request_middleware(attr: TokenStream, item: TokenStream) -> TokenStream {
3381    request_middleware_macro(attr, item)
3382}
3383
3384/// Registers a function as a response middleware.
3385///
3386/// This attribute macro registers the decorated function to be executed as a middleware
3387/// for outgoing responses. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
3388///
3389/// # Note
3390///
3391/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
3392///
3393/// # Usage
3394///
3395/// ```rust
3396/// use hyperlane::*;
3397/// use hyperlane_macros::*;
3398///
3399/// #[response_middleware]
3400/// struct ResponseMiddleware1;
3401///
3402/// impl ServerHook for ResponseMiddleware1 {
3403///     async fn new(_ctx: &Context) -> Self {
3404///         Self
3405///     }
3406///
3407///     async fn handle(self, ctx: &Context) {}
3408/// }
3409/// ```
3410///
3411/// # Dependencies
3412///
3413/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
3414#[proc_macro_attribute]
3415pub fn response_middleware(attr: TokenStream, item: TokenStream) -> TokenStream {
3416    response_middleware_macro(attr, item)
3417}
3418
3419/// Registers a function as a panic hook.
3420///
3421/// This attribute macro registers the decorated function to handle panics that occur
3422/// during request processing. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
3423///
3424/// # Note
3425///
3426/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
3427///
3428/// # Usage
3429///
3430/// ```rust
3431/// use hyperlane::*;
3432/// use hyperlane_macros::*;
3433///
3434/// #[task_panic]
3435/// #[task_panic(1)]
3436/// #[task_panic("2")]
3437/// struct PanicHook;
3438///
3439/// impl ServerHook for PanicHook {
3440///     async fn new(_ctx: &Context) -> Self {
3441///         Self
3442///     }
3443///
3444///     #[epilogue_macros(response_body("task_panic"), send)]
3445///     async fn handle(self, ctx: &Context) {}
3446/// }
3447/// ```
3448///
3449/// # Dependencies
3450///
3451/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
3452#[proc_macro_attribute]
3453pub fn task_panic(attr: TokenStream, item: TokenStream) -> TokenStream {
3454    task_panic_macro(attr, item)
3455}
3456
3457/// Registers a function as a request error hook.
3458///
3459/// This attribute macro registers the decorated function to handle request errors that occur
3460/// during request processing. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
3461///
3462/// # Note
3463///
3464/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
3465///
3466/// # Usage
3467///
3468/// ```rust
3469/// use hyperlane::*;
3470/// use hyperlane_macros::*;
3471///
3472/// #[request_error]
3473/// #[request_error(1)]
3474/// #[request_error("2")]
3475/// struct RequestErrorHook;
3476///
3477/// impl ServerHook for RequestErrorHook {
3478///     async fn new(_ctx: &Context) -> Self {
3479///         Self
3480///     }
3481///
3482///     #[epilogue_macros(response_body("request_error"), send)]
3483///     async fn handle(self, ctx: &Context) {}
3484/// }
3485/// ```
3486///
3487/// # Dependencies
3488///
3489/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
3490#[proc_macro_attribute]
3491pub fn request_error(attr: TokenStream, item: TokenStream) -> TokenStream {
3492    request_error_macro(attr, item)
3493}
3494
3495/// Injects a list of macros before the decorated function.
3496///
3497/// The macros are applied in head-insertion order, meaning the first macro in the list
3498/// is the outermost macro.
3499///
3500/// # Usage
3501///
3502/// ```rust
3503/// use hyperlane::*;
3504/// use hyperlane_macros::*;
3505///
3506/// #[route("/prologue_macros")]
3507/// struct PrologueMacros;
3508///
3509/// impl ServerHook for PrologueMacros {
3510///     async fn new(_ctx: &Context) -> Self {
3511///         Self
3512///     }
3513///
3514///     #[prologue_macros(post_method, response_body("prologue_macros"), send)]
3515///     async fn handle(self, ctx: &Context) {}
3516/// }
3517/// ```
3518#[proc_macro_attribute]
3519pub fn prologue_macros(attr: TokenStream, item: TokenStream) -> TokenStream {
3520    prologue_macros_macro(attr, item)
3521}
3522
3523/// Injects a list of macros after the decorated function.
3524///
3525/// The macros are applied in tail-insertion order, meaning the last macro in the list
3526/// is the outermost macro.
3527///
3528/// # Usage
3529///
3530/// ```rust
3531/// use hyperlane::*;
3532/// use hyperlane_macros::*;
3533///
3534/// #[response_middleware(2)]
3535/// struct ResponseMiddleware2;
3536///
3537/// impl ServerHook for ResponseMiddleware2 {
3538///     async fn new(_ctx: &Context) -> Self {
3539///         Self
3540///     }
3541///
3542///     #[epilogue_macros(try_send, flush)]
3543///     async fn handle(self, ctx: &Context) {}
3544/// }
3545/// ```
3546#[proc_macro_attribute]
3547pub fn epilogue_macros(attr: TokenStream, item: TokenStream) -> TokenStream {
3548    epilogue_macros_macro(attr, item)
3549}
3550
3551/// Automatically tries to send the complete response after function execution.
3552///
3553/// This attribute macro ensures that the response (request headers and body) is automatically tried to be sent
3554/// to the client after the function completes execution.
3555///
3556/// # Usage
3557///
3558/// ```rust
3559/// use hyperlane::*;
3560/// use hyperlane_macros::*;
3561///
3562/// #[route("/try_send")]
3563/// struct TrySendTest;
3564///
3565/// impl ServerHook for TrySendTest {
3566///     async fn new(_ctx: &Context) -> Self {
3567///         Self
3568///     }
3569///
3570///     #[epilogue_macros(try_send)]
3571///     async fn handle(self, ctx: &Context) {}
3572/// }
3573///
3574/// impl TrySendTest {
3575///     #[try_send]
3576///     async fn try_send_with_ref_self(&self, ctx: &Context) {}
3577/// }
3578///
3579/// #[try_send]
3580/// async fn standalone_try_send_handler(ctx: &Context) {}
3581/// ```
3582///
3583/// The macro takes no parameters and should be applied directly to async functions
3584/// that accept a `&Context` parameter.
3585#[proc_macro_attribute]
3586pub fn try_send(_attr: TokenStream, item: TokenStream) -> TokenStream {
3587    try_send_macro(item, Position::Epilogue)
3588}
3589
3590/// Automatically sends the complete response after function execution.
3591///
3592/// This attribute macro ensures that the response (request headers and body) is automatically sent
3593/// to the client after the function completes execution.
3594///
3595/// # Usage
3596///
3597/// ```rust
3598/// use hyperlane::*;
3599/// use hyperlane_macros::*;
3600///
3601/// #[route("/send")]
3602/// struct SendTest;
3603///
3604/// impl ServerHook for SendTest {
3605///     async fn new(_ctx: &Context) -> Self {
3606///         Self
3607///     }
3608///
3609///     #[epilogue_macros(send)]
3610///     async fn handle(self, ctx: &Context) {}
3611/// }
3612///
3613/// impl SendTest {
3614///     #[send]
3615///     async fn send_with_ref_self(&self, ctx: &Context) {}
3616/// }
3617///
3618/// #[send]
3619/// async fn standalone_send_handler(ctx: &Context) {}
3620/// ```
3621///
3622/// The macro takes no parameters and should be applied directly to async functions
3623/// that accept a `&Context` parameter.
3624///
3625/// # Panics
3626///
3627/// This macro will panic if the send operation fails.
3628#[proc_macro_attribute]
3629pub fn send(_attr: TokenStream, item: TokenStream) -> TokenStream {
3630    send_macro(item, Position::Epilogue)
3631}
3632
3633/// Automatically tries to send only the response body after function execution.
3634///
3635/// This attribute macro ensures that only the response body is automatically tried to be sent
3636/// to the client after the function completes, handling request headers separately.
3637///
3638/// # Usage
3639///
3640/// ```rust
3641/// use hyperlane::*;
3642/// use hyperlane_macros::*;
3643///
3644/// #[route("/try_send_body")]
3645/// struct TrySendBodyTest;
3646///
3647/// impl ServerHook for TrySendBodyTest {
3648///     async fn new(_ctx: &Context) -> Self {
3649///         Self
3650///     }
3651///
3652///     #[epilogue_macros(try_send_body)]
3653///     async fn handle(self, ctx: &Context) {}
3654/// }
3655///
3656/// impl TrySendBodyTest {
3657///     #[try_send_body]
3658///     async fn try_send_body_with_ref_self(&self, ctx: &Context) {}
3659/// }
3660///
3661/// #[try_send_body]
3662/// async fn standalone_try_send_body_handler(ctx: &Context) {}
3663/// ```
3664///
3665/// The macro takes no parameters and should be applied directly to async functions
3666/// that accept a `&Context` parameter.
3667#[proc_macro_attribute]
3668pub fn try_send_body(_attr: TokenStream, item: TokenStream) -> TokenStream {
3669    try_send_body_macro(item, Position::Epilogue)
3670}
3671
3672/// Automatically sends only the response body after function execution.
3673///
3674/// This attribute macro ensures that only the response body is automatically sent
3675/// to the client after the function completes, handling request headers separately.
3676///
3677/// # Usage
3678///
3679/// ```rust
3680/// use hyperlane::*;
3681/// use hyperlane_macros::*;
3682///
3683/// #[route("/send_body")]
3684/// struct SendBodyTest;
3685///
3686/// impl ServerHook for SendBodyTest {
3687///     async fn new(_ctx: &Context) -> Self {
3688///         Self
3689///     }
3690///
3691///     #[epilogue_macros(send_body)]
3692///     async fn handle(self, ctx: &Context) {}
3693/// }
3694///
3695/// impl SendBodyTest {
3696///     #[send_body]
3697///     async fn send_body_with_ref_self(&self, ctx: &Context) {}
3698/// }
3699///
3700/// #[send_body]
3701/// async fn standalone_send_body_handler(ctx: &Context) {}
3702/// ```
3703///
3704/// The macro takes no parameters and should be applied directly to async functions
3705/// that accept a `&Context` parameter.
3706///
3707/// # Panics
3708///
3709/// This macro will panic if the send body operation fails.
3710#[proc_macro_attribute]
3711pub fn send_body(_attr: TokenStream, item: TokenStream) -> TokenStream {
3712    send_body_macro(item, Position::Epilogue)
3713}
3714
3715/// Tries to send only the response body with data after function execution.
3716///
3717/// This attribute macro ensures that only the response body is automatically tried to be sent
3718/// to the client after the function completes, handling request headers separately,
3719/// with the specified data.
3720///
3721/// # Usage
3722///
3723/// ```rust
3724/// use hyperlane::*;
3725/// use hyperlane_macros::*;
3726///
3727/// #[route("/try_send_body_with_data")]
3728/// struct TrySendBodyWithData;
3729///
3730/// impl ServerHook for TrySendBodyWithData {
3731///     async fn new(_ctx: &Context) -> Self {
3732///         Self
3733///     }
3734///
3735///     #[epilogue_macros(try_send_body_with_data("Response body content"))]
3736///     async fn handle(self, ctx: &Context) {}
3737/// }
3738/// ```
3739///
3740/// The macro accepts data to send and should be applied to async functions
3741/// that accept a `&Context` parameter.
3742#[proc_macro_attribute]
3743pub fn try_send_body_with_data(attr: TokenStream, item: TokenStream) -> TokenStream {
3744    try_send_body_with_data_macro(attr, item, Position::Epilogue)
3745}
3746
3747/// Sends only the response body with data after function execution.
3748///
3749/// This attribute macro ensures that only the response body is automatically sent
3750/// to the client after the function completes, handling request headers separately,
3751/// with the specified data.
3752///
3753/// # Usage
3754///
3755/// ```rust
3756/// use hyperlane::*;
3757/// use hyperlane_macros::*;
3758///
3759/// #[route("/send_body_with_data")]
3760/// struct SendBodyWithData;
3761///
3762/// impl ServerHook for SendBodyWithData {
3763///     async fn new(_ctx: &Context) -> Self {
3764///         Self
3765///     }
3766///
3767///     #[epilogue_macros(send_body_with_data("Response body content"))]
3768///     async fn handle(self, ctx: &Context) {}
3769/// }
3770/// ```
3771///
3772/// The macro accepts data to send and should be applied to async functions
3773/// that accept a `&Context` parameter.
3774///
3775/// # Panics
3776///
3777/// This macro will panic if the send body with data operation fails.
3778#[proc_macro_attribute]
3779pub fn send_body_with_data(attr: TokenStream, item: TokenStream) -> TokenStream {
3780    send_body_with_data_macro(attr, item, Position::Epilogue)
3781}
3782
3783/// Tries to flush the response stream after function execution.
3784///
3785/// This attribute macro ensures that the response stream is tried to be flushed to guarantee immediate
3786/// data transmission, forcing any buffered response data to be sent to the client. This will not panic on failure.
3787///
3788/// # Usage
3789///
3790/// ```rust
3791/// use hyperlane::*;
3792/// use hyperlane_macros::*;
3793///
3794/// #[route("/try_flush")]
3795/// struct TryFlushTest;
3796///
3797/// impl ServerHook for TryFlushTest {
3798///     async fn new(_ctx: &Context) -> Self {
3799///         Self
3800///     }
3801///
3802///     #[epilogue_macros(try_flush)]
3803///     async fn handle(self, ctx: &Context) {}
3804/// }
3805///
3806/// impl TryFlushTest {
3807///     #[try_flush]
3808///     async fn try_flush_with_ref_self(&self, ctx: &Context) {}
3809/// }
3810///
3811/// #[try_flush]
3812/// async fn standalone_try_flush_handler(ctx: &Context) {}
3813/// ```
3814///
3815/// The macro takes no parameters and should be applied directly to async functions
3816/// that accept a `&Context` parameter.
3817#[proc_macro_attribute]
3818pub fn try_flush(_attr: TokenStream, item: TokenStream) -> TokenStream {
3819    try_flush_macro(item, Position::Prologue)
3820}
3821
3822/// Flushes the response stream after function execution.
3823///
3824/// This attribute macro ensures that the response stream is flushed to guarantee immediate
3825/// data transmission, forcing any buffered response data to be sent to the client.
3826///
3827/// # Usage
3828///
3829/// ```rust
3830/// use hyperlane::*;
3831/// use hyperlane_macros::*;
3832///
3833/// #[route("/flush")]
3834/// struct FlushTest;
3835///
3836/// impl ServerHook for FlushTest {
3837///     async fn new(_ctx: &Context) -> Self {
3838///         Self
3839///     }
3840///
3841///     #[epilogue_macros(flush)]
3842///     async fn handle(self, ctx: &Context) {}
3843/// }
3844///
3845/// impl FlushTest {
3846///     #[flush]
3847///     async fn flush_with_ref_self(&self, ctx: &Context) {}
3848/// }
3849///
3850/// #[flush]
3851/// async fn standalone_flush_handler(ctx: &Context) {}
3852/// ```
3853///
3854/// The macro takes no parameters and should be applied directly to async functions
3855/// that accept a `&Context` parameter.
3856///
3857/// # Panics
3858///
3859/// This macro will panic if the flush operation fails.
3860#[proc_macro_attribute]
3861pub fn flush(_attr: TokenStream, item: TokenStream) -> TokenStream {
3862    flush_macro(item, Position::Prologue)
3863}