Skip to main content

hyperlane_macros/
lib.rs

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