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