hyperlane_macros/
lib.rs

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