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")]
557/// struct Response;
558///
559/// impl ServerHook for Response {
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 Response {
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")]
598/// struct Response;
599///
600/// impl ServerHook for Response {
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 Response {
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")]
641/// struct Response;
642///
643/// impl ServerHook for Response {
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 Response {
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")]
697/// struct Response;
698///
699/// impl ServerHook for Response {
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 Response {
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("/unknown_method")]
735/// struct UnknownMethod;
736///
737/// impl ServerHook for UnknownMethod {
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("unknown_method")
746///     )]
747///     async fn handle(self, ctx: &Context) {}
748/// }
749///
750/// impl UnknownMethod {
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.
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///
1696/// # Usage
1697///
1698/// ```rust
1699/// use hyperlane::*;
1700/// use hyperlane_macros::*;
1701/// use serde::{Deserialize, Serialize};
1702///
1703/// #[derive(Debug, Serialize, Deserialize, Clone)]
1704/// struct TestData {
1705///     name: String,
1706///     age: u32,
1707/// }
1708///
1709/// #[route("/request_body_json")]
1710/// struct RequestBodyJson;
1711///
1712/// impl ServerHook for RequestBodyJson {
1713///     async fn new(_ctx: &Context) -> Self {
1714///         Self
1715///     }
1716///
1717///     #[response_body(&format!("request data: {request_data_result:?}"))]
1718///     #[request_body_json(request_data_result: TestData)]
1719///     async fn handle(self, ctx: &Context) {}
1720/// }
1721///
1722/// impl RequestBodyJson {
1723///     #[request_body_json(request_data_result: TestData)]
1724///     async fn request_body_json_with_ref_self(&self, ctx: &Context) {}
1725/// }
1726///
1727/// #[request_body_json(request_data_result: TestData)]
1728/// async fn standalone_request_body_json_handler(ctx: &Context) {}
1729/// ```
1730///
1731/// # Multi-Parameter Usage
1732///
1733/// ```rust
1734/// use hyperlane::*;
1735/// use hyperlane_macros::*;
1736/// use serde::{Deserialize, Serialize};
1737///
1738/// #[derive(Debug, Serialize, Deserialize, Clone)]
1739/// struct User {
1740///     name: String,
1741/// }
1742///
1743/// #[derive(Debug, Serialize, Deserialize, Clone)]
1744/// struct Config {
1745///     debug: bool,
1746/// }
1747///
1748/// #[route("/multi_json")]
1749/// struct MultiJson;
1750///
1751/// impl ServerHook for MultiJson {
1752///     async fn new(_ctx: &Context) -> Self {
1753///         Self
1754///     }
1755///
1756///     #[response_body(&format!("user: {user:?}, config: {config:?}"))]
1757///     #[request_body_json(user: User, config: Config)]
1758///     async fn handle(self, ctx: &Context) {}
1759/// }
1760/// ```
1761///
1762/// The macro accepts one or more `variable_name: Type` pairs separated by commas.
1763/// Each variable will be available in the function scope as a `ResultJsonError<Type>`.
1764#[proc_macro_attribute]
1765pub fn request_body_json(attr: TokenStream, item: TokenStream) -> TokenStream {
1766    request_body_json_macro(attr, item, Position::Prologue)
1767}
1768
1769/// Extracts a specific attribute value into a variable.
1770///
1771/// This attribute macro retrieves a specific attribute by key and makes it available
1772/// as a typed variable from the request context.
1773///
1774/// # Usage
1775///
1776/// ```rust
1777/// use hyperlane::*;
1778/// use hyperlane_macros::*;
1779/// use serde::{Deserialize, Serialize};
1780///
1781/// const TEST_ATTRIBUTE_KEY: &str = "test_attribute_key";
1782///
1783/// #[derive(Debug, Serialize, Deserialize, Clone)]
1784/// struct TestData {
1785///     name: String,
1786///     age: u32,
1787/// }
1788///
1789/// #[route("/attribute_option")]
1790/// struct Attribute;
1791///
1792/// impl ServerHook for Attribute {
1793///     async fn new(_ctx: &Context) -> Self {
1794///         Self
1795///     }
1796///
1797///     #[response_body(&format!("request attribute: {request_attribute_option:?}"))]
1798///     #[attribute_option(TEST_ATTRIBUTE_KEY => request_attribute_option: TestData)]
1799///     async fn handle(self, ctx: &Context) {}
1800/// }
1801///
1802/// impl Attribute {
1803///     #[attribute_option(TEST_ATTRIBUTE_KEY => request_attribute_option: TestData)]
1804///     async fn attribute_with_ref_self(&self, ctx: &Context) {}
1805/// }
1806///
1807/// #[attribute_option(TEST_ATTRIBUTE_KEY => request_attribute_option: TestData)]
1808/// async fn standalone_attribute_handler(ctx: &Context) {}
1809/// ```
1810///
1811/// The macro accepts a key-to-variable mapping in the format `key => variable_name: Type`.
1812/// The variable will be available as an `Option<Type>` in the function scope.
1813///
1814/// # Multi-Parameter Usage
1815///
1816/// ```rust
1817/// use hyperlane::*;
1818/// use hyperlane_macros::*;
1819///
1820/// #[route("/multi_attr")]
1821/// struct MultiAttr;
1822///
1823/// impl ServerHook for MultiAttr {
1824///     async fn new(_ctx: &Context) -> Self {
1825///         Self
1826///     }
1827///
1828///     #[response_body(&format!("attrs: {attr1:?}, {attr2:?}"))]
1829///     #[attribute_option("key1" => attr1: String, "key2" => attr2: i32)]
1830///     async fn handle(self, ctx: &Context) {}
1831/// }
1832/// ```
1833///
1834/// The macro accepts multiple `key => variable_name: Type` tuples separated by commas.
1835#[proc_macro_attribute]
1836pub fn attribute_option(attr: TokenStream, item: TokenStream) -> TokenStream {
1837    attribute_option_macro(attr, item, Position::Prologue)
1838}
1839
1840/// Extracts a specific attribute value into a variable.
1841///
1842/// This attribute macro retrieves a specific attribute by key and makes it available
1843/// as a typed variable from the request context.
1844///
1845/// # Usage
1846///
1847/// ```rust
1848/// use hyperlane::*;
1849/// use hyperlane_macros::*;
1850/// use serde::{Deserialize, Serialize};
1851///
1852/// const TEST_ATTRIBUTE_KEY: &str = "test_attribute_key";
1853///
1854/// #[derive(Debug, Serialize, Deserialize, Clone)]
1855/// struct TestData {
1856///     name: String,
1857///     age: u32,
1858/// }
1859///
1860/// #[route("/attribute")]
1861/// struct Attribute;
1862///
1863/// impl ServerHook for Attribute {
1864///     async fn new(_ctx: &Context) -> Self {
1865///         Self
1866///     }
1867///
1868///     #[response_body(&format!("request attribute: {request_attribute:?}"))]
1869///     #[attribute(TEST_ATTRIBUTE_KEY => request_attribute: TestData)]
1870///     async fn handle(self, ctx: &Context) {}
1871/// }
1872///
1873/// impl Attribute {
1874///     #[attribute(TEST_ATTRIBUTE_KEY => request_attribute: TestData)]
1875///     async fn attribute_with_ref_self(&self, ctx: &Context) {}
1876/// }
1877///
1878/// #[attribute(TEST_ATTRIBUTE_KEY => request_attribute: TestData)]
1879/// async fn standalone_attribute_handler(ctx: &Context) {}
1880/// ```
1881///
1882/// The macro accepts a key-to-variable mapping in the format `key => variable_name: Type`.
1883/// The variable will be available as an `Type` in the function scope.
1884///
1885/// # Multi-Parameter Usage
1886///
1887/// ```rust
1888/// use hyperlane::*;
1889/// use hyperlane_macros::*;
1890///
1891/// #[route("/multi_attr")]
1892/// struct MultiAttr;
1893///
1894/// impl ServerHook for MultiAttr {
1895///     async fn new(_ctx: &Context) -> Self {
1896///         Self
1897///     }
1898///
1899///     #[response_body(&format!("attrs: {attr1}, {attr2}"))]
1900///     #[attribute("key1" => attr1: String, "key2" => attr2: i32)]
1901///     async fn handle(self, ctx: &Context) {}
1902/// }
1903/// ```
1904///
1905/// The macro accepts multiple `key => variable_name: Type` tuples separated by commas.
1906#[proc_macro_attribute]
1907pub fn attribute(attr: TokenStream, item: TokenStream) -> TokenStream {
1908    attribute_macro(attr, item, Position::Prologue)
1909}
1910
1911/// Extracts all attributes into a ThreadSafeAttributeStore variable.
1912///
1913/// This attribute macro retrieves all available attributes from the request context
1914/// and makes them available as a ThreadSafeAttributeStore for comprehensive attribute access.
1915///
1916/// # Usage
1917///
1918/// ```rust
1919/// use hyperlane::*;
1920/// use hyperlane_macros::*;
1921///
1922/// #[route("/attributes")]
1923/// struct Attributes;
1924///
1925/// impl ServerHook for Attributes {
1926///     async fn new(_ctx: &Context) -> Self {
1927///         Self
1928///     }
1929///
1930///     #[response_body(&format!("request attributes: {request_attributes:?}"))]
1931///     #[attributes(request_attributes)]
1932///     async fn handle(self, ctx: &Context) {}
1933/// }
1934///
1935/// impl Attributes {
1936///     #[attributes(request_attributes)]
1937///     async fn attributes_with_ref_self(&self, ctx: &Context) {}
1938/// }
1939///
1940/// #[attributes(request_attributes)]
1941/// async fn standalone_attributes_handler(ctx: &Context) {}
1942/// ```
1943///
1944/// The macro accepts a variable name that will contain a HashMap of all attributes.
1945/// The variable will be available as a HashMap in the function scope.
1946///
1947/// # Multi-Parameter Usage
1948///
1949/// ```rust
1950/// use hyperlane::*;
1951/// use hyperlane_macros::*;
1952///
1953/// #[route("/multi_attrs")]
1954/// struct MultiAttrs;
1955///
1956/// impl ServerHook for MultiAttrs {
1957///     async fn new(_ctx: &Context) -> Self {
1958///         Self
1959///     }
1960///
1961///     #[response_body(&format!("attrs1: {attrs1:?}, attrs2: {attrs2:?}"))]
1962///     #[attributes(attrs1, attrs2)]
1963///     async fn handle(self, ctx: &Context) {}
1964/// }
1965/// ```
1966///
1967/// The macro accepts multiple variable names separated by commas.
1968#[proc_macro_attribute]
1969pub fn attributes(attr: TokenStream, item: TokenStream) -> TokenStream {
1970    attributes_macro(attr, item, Position::Prologue)
1971}
1972
1973/// Extracts a specific route parameter into a variable.
1974///
1975/// This attribute macro retrieves a specific route parameter by key and makes it
1976/// available as a variable. Route parameters are extracted from the URL path segments.
1977///
1978/// # Usage
1979///
1980/// ```rust
1981/// use hyperlane::*;
1982/// use hyperlane_macros::*;
1983///
1984/// #[route("/route_param_option/:test")]
1985/// struct RouteParam;
1986///
1987/// impl ServerHook for RouteParam {
1988///     async fn new(_ctx: &Context) -> Self {
1989///         Self
1990///     }
1991///
1992///     #[response_body(&format!("route param: {request_route_param:?}"))]
1993///     #[route_param_option("test" => request_route_param)]
1994///     async fn handle(self, ctx: &Context) {}
1995/// }
1996///
1997/// impl RouteParam {
1998///     #[route_param_option("test" => request_route_param)]
1999///     async fn route_param_with_ref_self(&self, ctx: &Context) {}
2000/// }
2001///
2002/// #[route_param_option("test" => request_route_param)]
2003/// async fn standalone_route_param_handler(ctx: &Context) {}
2004/// ```
2005///
2006/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2007/// The variable will be available as an `OptionString` in the function scope.
2008///
2009/// # Multi-Parameter Usage
2010///
2011/// ```rust
2012/// use hyperlane::*;
2013/// use hyperlane_macros::*;
2014///
2015/// #[route("/multi_param/:id/:name")]
2016/// struct MultiParam;
2017///
2018/// impl ServerHook for MultiParam {
2019///     async fn new(_ctx: &Context) -> Self {
2020///         Self
2021///     }
2022///
2023///     #[response_body(&format!("id: {id:?}, name: {name:?}"))]
2024///     #[route_param_option("id" => id, "name" => name)]
2025///     async fn handle(self, ctx: &Context) {}
2026/// }
2027/// ```
2028///
2029/// The macro accepts multiple `"key" => variable_name` pairs separated by commas.
2030#[proc_macro_attribute]
2031pub fn route_param_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2032    route_param_option_macro(attr, item, Position::Prologue)
2033}
2034
2035/// Extracts a specific route parameter into a variable.
2036///
2037/// This attribute macro retrieves a specific route parameter by key and makes it
2038/// available as a variable. Route parameters are extracted from the URL path segments.
2039///
2040/// # Usage
2041///
2042/// ```rust
2043/// use hyperlane::*;
2044/// use hyperlane_macros::*;
2045///
2046/// #[route("/route_param/:test")]
2047/// struct RouteParam;
2048///
2049/// impl ServerHook for RouteParam {
2050///     async fn new(_ctx: &Context) -> Self {
2051///         Self
2052///     }
2053///
2054///     #[response_body(&format!("route param: {request_route_param:?}"))]
2055///     #[route_param("test" => request_route_param)]
2056///     async fn handle(self, ctx: &Context) {}
2057/// }
2058///
2059/// impl RouteParam {
2060///     #[route_param("test" => request_route_param)]
2061///     async fn route_param_with_ref_self(&self, ctx: &Context) {}
2062/// }
2063///
2064/// #[route_param("test" => request_route_param)]
2065/// async fn standalone_route_param_handler(ctx: &Context) {}
2066/// ```
2067///
2068/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2069/// The variable will be available as an `String` in the function scope.
2070///
2071/// # Multi-Parameter Usage
2072///
2073/// ```rust
2074/// use hyperlane::*;
2075/// use hyperlane_macros::*;
2076///
2077/// #[route("/multi_param/:id/:name")]
2078/// struct MultiParam;
2079///
2080/// impl ServerHook for MultiParam {
2081///     async fn new(_ctx: &Context) -> Self {
2082///         Self
2083///     }
2084///
2085///     #[response_body(&format!("id: {id:?}, name: {name:?}"))]
2086///     #[route_param("id" => id, "name" => name)]
2087///     async fn handle(self, ctx: &Context) {}
2088/// }
2089/// ```
2090///
2091/// The macro accepts multiple `"key" => variable_name` pairs separated by commas.
2092#[proc_macro_attribute]
2093pub fn route_param(attr: TokenStream, item: TokenStream) -> TokenStream {
2094    route_param_macro(attr, item, Position::Prologue)
2095}
2096
2097/// Extracts all route parameters into a collection variable.
2098///
2099/// This attribute macro retrieves all available route parameters from the URL path
2100/// and makes them available as a collection for comprehensive route parameter access.
2101///
2102/// # Usage
2103///
2104/// ```rust
2105/// use hyperlane::*;
2106/// use hyperlane_macros::*;
2107///
2108/// #[route("/route_params/:test")]
2109/// struct RouteParams;
2110///
2111/// impl ServerHook for RouteParams {
2112///     async fn new(_ctx: &Context) -> Self {
2113///         Self
2114///     }
2115///
2116///     #[response_body(&format!("request route params: {request_route_params:?}"))]
2117///     #[route_params(request_route_params)]
2118///     async fn handle(self, ctx: &Context) {}
2119/// }
2120///
2121/// impl RouteParams {
2122///     #[route_params(request_route_params)]
2123///     async fn route_params_with_ref_self(&self, ctx: &Context) {}
2124/// }
2125///
2126/// #[route_params(request_route_params)]
2127/// async fn standalone_route_params_handler(ctx: &Context) {}
2128/// ```
2129///
2130/// The macro accepts a variable name that will contain all route parameters.
2131/// The variable will be available as a RouteParams type in the function scope.
2132///
2133/// # Multi-Parameter Usage
2134///
2135/// ```rust
2136/// use hyperlane::*;
2137/// use hyperlane_macros::*;
2138///
2139/// #[route("/multi_params/:id")]
2140/// struct MultiParams;
2141///
2142/// impl ServerHook for MultiParams {
2143///     async fn new(_ctx: &Context) -> Self {
2144///         Self
2145///     }
2146///
2147///     #[response_body(&format!("params1: {params1:?}, params2: {params2:?}"))]
2148///     #[route_params(params1, params2)]
2149///     async fn handle(self, ctx: &Context) {}
2150/// }
2151/// ```
2152///
2153/// The macro accepts multiple variable names separated by commas.
2154#[proc_macro_attribute]
2155pub fn route_params(attr: TokenStream, item: TokenStream) -> TokenStream {
2156    route_params_macro(attr, item, Position::Prologue)
2157}
2158
2159/// Extracts a specific request query parameter into a variable.
2160///
2161/// This attribute macro retrieves a specific request query parameter by key and makes it
2162/// available as a variable. Query parameters are extracted from the URL request query string.
2163///
2164/// # Usage
2165///
2166/// ```rust
2167/// use hyperlane::*;
2168/// use hyperlane_macros::*;
2169///
2170/// #[route("/request_query_option")]
2171/// struct RequestQuery;
2172///
2173/// impl ServerHook for RequestQuery {
2174///     async fn new(_ctx: &Context) -> Self {
2175///         Self
2176///     }
2177///
2178///     #[prologue_macros(
2179///         request_query_option("test" => request_query_option),
2180///         response_body(&format!("request query: {request_query_option:?}")),
2181///         send
2182///     )]
2183///     async fn handle(self, ctx: &Context) {}
2184/// }
2185///
2186/// impl RequestQuery {
2187///     #[request_query_option("test" => request_query_option)]
2188///     async fn request_query_with_ref_self(&self, ctx: &Context) {}
2189/// }
2190///
2191/// #[request_query_option("test" => request_query_option)]
2192/// async fn standalone_request_query_handler(ctx: &Context) {}
2193/// ```
2194///
2195/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2196/// The variable will be available as an `OptionRequestQuerysValue` in the function scope.
2197///
2198/// Supports multiple parameters: `#[request_query_option("k1" => v1, "k2" => v2)]`
2199#[proc_macro_attribute]
2200pub fn request_query_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2201    request_query_option_macro(attr, item, Position::Prologue)
2202}
2203
2204/// Extracts a specific request query parameter into a variable.
2205///
2206/// This attribute macro retrieves a specific request query parameter by key and makes it
2207/// available as a variable. Query parameters are extracted from the URL request query string.
2208///
2209/// # Usage
2210///
2211/// ```rust
2212/// use hyperlane::*;
2213/// use hyperlane_macros::*;
2214///
2215/// #[route("/request_query")]
2216/// struct RequestQuery;
2217///
2218/// impl ServerHook for RequestQuery {
2219///     async fn new(_ctx: &Context) -> Self {
2220///         Self
2221///     }
2222///
2223///     #[prologue_macros(
2224///         request_query("test" => request_query),
2225///         response_body(&format!("request query: {request_query}")),
2226///         send
2227///     )]
2228///     async fn handle(self, ctx: &Context) {}
2229/// }
2230///
2231/// impl RequestQuery {
2232///     #[request_query("test" => request_query)]
2233///     async fn request_query_with_ref_self(&self, ctx: &Context) {}
2234/// }
2235///
2236/// #[request_query("test" => request_query)]
2237/// async fn standalone_request_query_handler(ctx: &Context) {}
2238/// ```
2239///
2240/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
2241/// The variable will be available as an `RequestQuerysValue` in the function scope.
2242///
2243/// Supports multiple parameters: `#[request_query("k1" => v1, "k2" => v2)]`
2244#[proc_macro_attribute]
2245pub fn request_query(attr: TokenStream, item: TokenStream) -> TokenStream {
2246    request_query_macro(attr, item, Position::Prologue)
2247}
2248
2249/// Extracts all request query parameters into a RequestQuerys variable.
2250///
2251/// This attribute macro retrieves all available request query parameters from the URL request query string
2252/// and makes them available as a RequestQuerys for comprehensive request query parameter access.
2253///
2254/// # Usage
2255///
2256/// ```rust
2257/// use hyperlane::*;
2258/// use hyperlane_macros::*;
2259///
2260/// #[route("/request_querys")]
2261/// struct RequestQuerys;
2262///
2263/// impl ServerHook for RequestQuerys {
2264///     async fn new(_ctx: &Context) -> Self {
2265///         Self
2266///     }
2267///
2268///     #[prologue_macros(
2269///         request_querys(request_querys),
2270///         response_body(&format!("request querys: {request_querys:?}")),
2271///         send
2272///     )]
2273///     async fn handle(self, ctx: &Context) {}
2274/// }
2275///
2276/// impl RequestQuerys {
2277///     #[request_querys(request_querys)]
2278///     async fn request_querys_with_ref_self(&self, ctx: &Context) {}
2279/// }
2280///
2281/// #[request_querys(request_querys)]
2282/// async fn standalone_request_querys_handler(ctx: &Context) {}
2283/// ```
2284///
2285/// The macro accepts a variable name that will contain all request query parameters.
2286/// The variable will be available as a collection in the function scope.
2287///
2288/// Supports multiple parameters: `#[request_querys(querys1, querys2)]`
2289#[proc_macro_attribute]
2290pub fn request_querys(attr: TokenStream, item: TokenStream) -> TokenStream {
2291    request_querys_macro(attr, item, Position::Prologue)
2292}
2293
2294/// Extracts a specific HTTP request header into a variable.
2295///
2296/// This attribute macro retrieves a specific HTTP request header by name and makes it
2297/// available as a variable. Header values are extracted from the request request headers collection.
2298///
2299/// # Usage
2300///
2301/// ```rust
2302/// use hyperlane::*;
2303/// use hyperlane_macros::*;
2304///
2305/// #[route("/request_header_option")]
2306/// struct RequestHeader;
2307///
2308/// impl ServerHook for RequestHeader {
2309///     async fn new(_ctx: &Context) -> Self {
2310///         Self
2311///     }
2312///
2313///     #[prologue_macros(
2314///         request_header_option(HOST => request_header_option),
2315///         response_body(&format!("request header: {request_header_option:?}")),
2316///         send
2317///     )]
2318///     async fn handle(self, ctx: &Context) {}
2319/// }
2320///
2321/// impl RequestHeader {
2322///     #[request_header_option(HOST => request_header_option)]
2323///     async fn request_header_with_ref_self(&self, ctx: &Context) {}
2324/// }
2325///
2326/// #[request_header_option(HOST => request_header_option)]
2327/// async fn standalone_request_header_handler(ctx: &Context) {}
2328/// ```
2329///
2330/// The macro accepts a request header name-to-variable mapping in the format `HEADER_NAME => variable_name`
2331/// or `"Header-Name" => variable_name`. The variable will be available as an `OptionRequestHeadersValueItem`.
2332#[proc_macro_attribute]
2333pub fn request_header_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2334    request_header_option_macro(attr, item, Position::Prologue)
2335}
2336
2337/// Extracts a specific HTTP request header into a variable.
2338///
2339/// This attribute macro retrieves a specific HTTP request header by name and makes it
2340/// available as a variable. Header values are extracted from the request request headers collection.
2341///
2342/// # Usage
2343///
2344/// ```rust
2345/// use hyperlane::*;
2346/// use hyperlane_macros::*;
2347///
2348/// #[route("/request_header")]
2349/// struct RequestHeader;
2350///
2351/// impl ServerHook for RequestHeader {
2352///     async fn new(_ctx: &Context) -> Self {
2353///         Self
2354///     }
2355///
2356///     #[prologue_macros(
2357///         request_header(HOST => request_header),
2358///         response_body(&format!("request header: {request_header}")),
2359///         send
2360///     )]
2361///     async fn handle(self, ctx: &Context) {}
2362/// }
2363///
2364/// impl RequestHeader {
2365///     #[request_header(HOST => request_header)]
2366///     async fn request_header_with_ref_self(&self, ctx: &Context) {}
2367/// }
2368///
2369/// #[request_header(HOST => request_header)]
2370/// async fn standalone_request_header_handler(ctx: &Context) {}
2371/// ```
2372///
2373/// The macro accepts a request header name-to-variable mapping in the format `HEADER_NAME => variable_name`
2374/// or `"Header-Name" => variable_name`. The variable will be available as an `RequestHeadersValueItem`.
2375#[proc_macro_attribute]
2376pub fn request_header(attr: TokenStream, item: TokenStream) -> TokenStream {
2377    request_header_macro(attr, item, Position::Prologue)
2378}
2379
2380/// Extracts all HTTP request headers into a collection variable.
2381///
2382/// This attribute macro retrieves all available HTTP request headers from the request
2383/// and makes them available as a collection for comprehensive request header access.
2384///
2385/// # Usage
2386///
2387/// ```rust
2388/// use hyperlane::*;
2389/// use hyperlane_macros::*;
2390///
2391/// #[route("/request_headers")]
2392/// struct RequestHeaders;
2393///
2394/// impl ServerHook for RequestHeaders {
2395///     async fn new(_ctx: &Context) -> Self {
2396///         Self
2397///     }
2398///
2399///     #[prologue_macros(
2400///         request_headers(request_headers),
2401///         response_body(&format!("request headers: {request_headers:?}")),
2402///         send
2403///     )]
2404///     async fn handle(self, ctx: &Context) {}
2405/// }
2406///
2407/// impl RequestHeaders {
2408///     #[request_headers(request_headers)]
2409///     async fn request_headers_with_ref_self(&self, ctx: &Context) {}
2410/// }
2411///
2412/// #[request_headers(request_headers)]
2413/// async fn standalone_request_headers_handler(ctx: &Context) {}
2414/// ```
2415///
2416/// The macro accepts a variable name that will contain all HTTP request headers.
2417/// The variable will be available as a RequestHeaders type in the function scope.
2418#[proc_macro_attribute]
2419pub fn request_headers(attr: TokenStream, item: TokenStream) -> TokenStream {
2420    request_headers_macro(attr, item, Position::Prologue)
2421}
2422
2423/// Extracts a specific cookie value or all cookies into a variable.
2424///
2425/// This attribute macro supports two syntaxes:
2426/// 1. `cookie(key => variable_name)` - Extract a specific cookie value by key
2427/// 2. `cookie(variable_name)` - Extract all cookies as a raw string
2428///
2429/// # Usage
2430///
2431/// ```rust
2432/// use hyperlane::*;
2433/// use hyperlane_macros::*;
2434///
2435/// #[route("/cookie")]
2436/// struct Cookie;
2437///
2438/// impl ServerHook for Cookie {
2439///     async fn new(_ctx: &Context) -> Self {
2440///         Self
2441///     }
2442///
2443///     #[response_body(&format!("Session cookie: {session_cookie1_option:?}, {session_cookie2_option:?}"))]
2444///     #[request_cookie_option("test1" => session_cookie1_option, "test2" => session_cookie2_option)]
2445///     async fn handle(self, ctx: &Context) {}
2446/// }
2447///
2448/// impl Cookie {
2449///     #[response_body(&format!("Session cookie: {session_cookie1_option:?}, {session_cookie2_option:?}"))]
2450///     #[request_cookie_option("test1" => session_cookie1_option, "test2" => session_cookie2_option)]
2451///     async fn request_cookie_with_ref_self(&self, ctx: &Context) {}
2452/// }
2453///
2454/// #[response_body(&format!("Session cookie: {session_cookie1_option:?}, {session_cookie2_option:?}"))]
2455/// #[request_cookie_option("test1" => session_cookie1_option, "test2" => session_cookie2_option)]
2456/// async fn standalone_request_cookie_handler(ctx: &Context) {}
2457/// ```
2458///
2459/// For specific cookie extraction, the variable will be available as `Option<String>`.
2460/// For all cookies extraction, the variable will be available as `String`.
2461#[proc_macro_attribute]
2462pub fn request_cookie_option(attr: TokenStream, item: TokenStream) -> TokenStream {
2463    request_cookie_option_macro(attr, item, Position::Prologue)
2464}
2465
2466/// Extracts a specific cookie value or all cookies into a variable.
2467///
2468/// This attribute macro supports two syntaxes:
2469/// 1. `cookie(key => variable_name)` - Extract a specific cookie value by key
2470/// 2. `cookie(variable_name)` - Extract all cookies as a raw string
2471///
2472/// # Usage
2473///
2474/// ```rust
2475/// use hyperlane::*;
2476/// use hyperlane_macros::*;
2477///
2478/// #[route("/cookie")]
2479/// struct Cookie;
2480///
2481/// impl ServerHook for Cookie {
2482///     async fn new(_ctx: &Context) -> Self {
2483///         Self
2484///     }
2485///
2486///     #[response_body(&format!("Session cookie: {session_cookie1}, {session_cookie2}"))]
2487///     #[request_cookie("test1" => session_cookie1, "test2" => session_cookie2)]
2488///     async fn handle(self, ctx: &Context) {}
2489/// }
2490///
2491/// impl Cookie {
2492///     #[response_body(&format!("Session cookie: {session_cookie1}, {session_cookie2}"))]
2493///     #[request_cookie("test1" => session_cookie1, "test2" => session_cookie2)]
2494///     async fn request_cookie_with_ref_self(&self, ctx: &Context) {}
2495/// }
2496///
2497/// #[response_body(&format!("Session cookie: {session_cookie1}, {session_cookie2}"))]
2498/// #[request_cookie("test1" => session_cookie1, "test2" => session_cookie2)]
2499/// async fn standalone_request_cookie_handler(ctx: &Context) {}
2500/// ```
2501///
2502/// For specific cookie extraction, the variable will be available as `String`.
2503/// For all cookies extraction, the variable will be available as `String`.
2504#[proc_macro_attribute]
2505pub fn request_cookie(attr: TokenStream, item: TokenStream) -> TokenStream {
2506    request_cookie_macro(attr, item, Position::Prologue)
2507}
2508
2509/// Extracts all cookies as a raw string into a variable.
2510///
2511/// This attribute macro retrieves the entire Cookie header from the request and makes it
2512/// available as a String variable. If no Cookie header is present, an empty string is used.
2513///
2514/// # Usage
2515///
2516/// ```rust
2517/// use hyperlane::*;
2518/// use hyperlane_macros::*;
2519///
2520/// #[route("/cookies")]
2521/// struct Cookies;
2522///
2523/// impl ServerHook for Cookies {
2524///     async fn new(_ctx: &Context) -> Self {
2525///         Self
2526///     }
2527///
2528///     #[response_body(&format!("All cookies: {cookie_value:?}"))]
2529///     #[request_cookies(cookie_value)]
2530///     async fn handle(self, ctx: &Context) {}
2531/// }
2532///
2533/// impl Cookies {
2534///     #[request_cookies(cookie_value)]
2535///     async fn request_cookies_with_ref_self(&self, ctx: &Context) {}
2536/// }
2537///
2538/// #[request_cookies(cookie_value)]
2539/// async fn standalone_request_cookies_handler(ctx: &Context) {}
2540/// ```
2541///
2542/// The macro accepts a variable name that will contain all cookies.
2543/// The variable will be available as a Cookies type in the function scope.
2544#[proc_macro_attribute]
2545pub fn request_cookies(attr: TokenStream, item: TokenStream) -> TokenStream {
2546    request_cookies_macro(attr, item, Position::Prologue)
2547}
2548
2549/// Extracts the HTTP request version into a variable.
2550///
2551/// This attribute macro retrieves the HTTP version from the request and makes it
2552/// available as a variable. The version represents the HTTP protocol version used.
2553///
2554/// # Usage
2555///
2556/// ```rust
2557/// use hyperlane::*;
2558/// use hyperlane_macros::*;
2559///
2560/// #[route("/request_version")]
2561/// struct RequestVersionTest;
2562///
2563/// impl ServerHook for RequestVersionTest {
2564///     async fn new(_ctx: &Context) -> Self {
2565///         Self
2566///     }
2567///
2568///     #[response_body(&format!("HTTP Version: {http_version}"))]
2569///     #[request_version(http_version)]
2570///     async fn handle(self, ctx: &Context) {}
2571/// }
2572///
2573/// impl RequestVersionTest {
2574///     #[request_version(http_version)]
2575///     async fn request_version_with_ref_self(&self, ctx: &Context) {}
2576/// }
2577///
2578/// #[request_version(http_version)]
2579/// async fn standalone_request_version_handler(ctx: &Context) {}
2580/// ```
2581///
2582/// The macro accepts a variable name that will contain the HTTP request version.
2583/// The variable will be available as a RequestVersion type in the function scope.
2584#[proc_macro_attribute]
2585pub fn request_version(attr: TokenStream, item: TokenStream) -> TokenStream {
2586    request_version_macro(attr, item, Position::Prologue)
2587}
2588
2589/// Extracts the HTTP request path into a variable.
2590///
2591/// This attribute macro retrieves the request path from the HTTP request and makes it
2592/// available as a variable. The path represents the URL path portion of the request.
2593///
2594/// # Usage
2595///
2596/// ```rust
2597/// use hyperlane::*;
2598/// use hyperlane_macros::*;
2599///
2600/// #[route("/request_path")]
2601/// struct RequestPathTest;
2602///
2603/// impl ServerHook for RequestPathTest {
2604///     async fn new(_ctx: &Context) -> Self {
2605///         Self
2606///     }
2607///
2608///     #[response_body(&format!("Request Path: {request_path}"))]
2609///     #[request_path(request_path)]
2610///     async fn handle(self, ctx: &Context) {}
2611/// }
2612///
2613/// impl RequestPathTest {
2614///     #[request_path(request_path)]
2615///     async fn request_path_with_ref_self(&self, ctx: &Context) {}
2616/// }
2617///
2618/// #[request_path(request_path)]
2619/// async fn standalone_request_path_handler(ctx: &Context) {}
2620/// ```
2621///
2622/// The macro accepts a variable name that will contain the HTTP request path.
2623/// The variable will be available as a RequestPath type in the function scope.
2624#[proc_macro_attribute]
2625pub fn request_path(attr: TokenStream, item: TokenStream) -> TokenStream {
2626    request_path_macro(attr, item, Position::Prologue)
2627}
2628
2629/// Creates a new instance of a specified type with a given variable name.
2630///
2631/// This attribute macro generates an instance initialization at the beginning of the function.
2632///
2633/// # Usage
2634///
2635/// ```rust,no_run
2636/// use hyperlane::*;
2637/// use hyperlane_macros::*;
2638///
2639/// #[hyperlane(server: Server)]
2640/// #[hyperlane(config: ServerConfig)]
2641/// #[tokio::main]
2642/// async fn main() {
2643///     config.disable_nodelay().await;
2644///     server.config(config).await;
2645///     let server_hook: ServerControlHook = server.run().await.unwrap_or_default();
2646///     server_hook.wait().await;
2647/// }
2648/// ```
2649///
2650/// The macro accepts a `variable_name: Type` pair.
2651/// The variable will be available as an instance of the specified type in the function scope.
2652#[proc_macro_attribute]
2653pub fn hyperlane(attr: TokenStream, item: TokenStream) -> TokenStream {
2654    hyperlane_macro(attr, item)
2655}
2656
2657/// Registers a function as a route handler.
2658///
2659/// This attribute macro registers the decorated function as a route handler for a given path.
2660/// This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
2661///
2662/// # Usage
2663///
2664/// ```rust
2665/// use hyperlane::*;
2666/// use hyperlane_macros::*;
2667///
2668/// #[route("/response")]
2669/// struct Response;
2670///
2671/// impl ServerHook for Response {
2672///     async fn new(_ctx: &Context) -> Self {
2673///         Self
2674///     }
2675///
2676///     #[response_body("response")]
2677///     async fn handle(self, ctx: &Context) {}
2678/// }
2679/// ```
2680///
2681/// # Parameters
2682///
2683/// - `path`: String literal defining the route path
2684///
2685/// # Dependencies
2686///
2687/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
2688#[proc_macro_attribute]
2689pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream {
2690    route_macro(attr, item)
2691}
2692
2693/// Registers a function as a request middleware.
2694///
2695/// This attribute macro registers the decorated function to be executed as a middleware
2696/// for incoming requests. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
2697///
2698/// # Note
2699///
2700/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
2701///
2702/// # Usage
2703///
2704/// ```rust
2705/// use hyperlane::*;
2706/// use hyperlane_macros::*;
2707///
2708/// #[request_middleware]
2709/// struct RequestMiddleware;
2710///
2711/// impl ServerHook for RequestMiddleware {
2712///     async fn new(_ctx: &Context) -> Self {
2713///         Self
2714///     }
2715///
2716///     #[epilogue_macros(
2717///         response_status_code(200),
2718///         response_version(HttpVersion::HTTP1_1),
2719///         response_header(SERVER => HYPERLANE)
2720///     )]
2721///     async fn handle(self, ctx: &Context) {}
2722/// }
2723/// ```
2724///
2725/// # Dependencies
2726///
2727/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
2728#[proc_macro_attribute]
2729pub fn request_middleware(attr: TokenStream, item: TokenStream) -> TokenStream {
2730    request_middleware_macro(attr, item)
2731}
2732
2733/// Registers a function as a response middleware.
2734///
2735/// This attribute macro registers the decorated function to be executed as a middleware
2736/// for outgoing responses. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
2737///
2738/// # Note
2739///
2740/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
2741///
2742/// # Usage
2743///
2744/// ```rust
2745/// use hyperlane::*;
2746/// use hyperlane_macros::*;
2747///
2748/// #[response_middleware]
2749/// struct ResponseMiddleware1;
2750///
2751/// impl ServerHook for ResponseMiddleware1 {
2752///     async fn new(_ctx: &Context) -> Self {
2753///         Self
2754///     }
2755///
2756///     async fn handle(self, ctx: &Context) {}
2757/// }
2758/// ```
2759///
2760/// # Dependencies
2761///
2762/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
2763#[proc_macro_attribute]
2764pub fn response_middleware(attr: TokenStream, item: TokenStream) -> TokenStream {
2765    response_middleware_macro(attr, item)
2766}
2767
2768/// Registers a function as a panic hook.
2769///
2770/// This attribute macro registers the decorated function to handle panics that occur
2771/// during request processing. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
2772///
2773/// # Note
2774///
2775/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
2776///
2777/// # Usage
2778///
2779/// ```rust
2780/// use hyperlane::*;
2781/// use hyperlane_macros::*;
2782///
2783/// #[panic_hook]
2784/// #[panic_hook(1)]
2785/// #[panic_hook("2")]
2786/// struct PanicHook;
2787///
2788/// impl ServerHook for PanicHook {
2789///     async fn new(_ctx: &Context) -> Self {
2790///         Self
2791///     }
2792///
2793///     #[epilogue_macros(response_body("panic_hook"), send)]
2794///     async fn handle(self, ctx: &Context) {}
2795/// }
2796/// ```
2797///
2798/// # Dependencies
2799///
2800/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
2801#[proc_macro_attribute]
2802pub fn panic_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
2803    panic_hook_macro(attr, item)
2804}
2805
2806/// Injects a list of macros before the decorated function.
2807///
2808/// The macros are applied in head-insertion order, meaning the first macro in the list
2809/// is the outermost macro.
2810///
2811/// # Usage
2812///
2813/// ```rust
2814/// use hyperlane::*;
2815/// use hyperlane_macros::*;
2816///
2817/// #[route("/post")]
2818/// struct Post;
2819///
2820/// impl ServerHook for Post {
2821///     async fn new(_ctx: &Context) -> Self {
2822///         Self
2823///     }
2824///
2825///     #[prologue_macros(post, response_body("post"), send)]
2826///     async fn handle(self, ctx: &Context) {}
2827/// }
2828/// ```
2829#[proc_macro_attribute]
2830pub fn prologue_macros(attr: TokenStream, item: TokenStream) -> TokenStream {
2831    prologue_macros_macro(attr, item)
2832}
2833
2834/// Injects a list of macros after the decorated function.
2835///
2836/// The macros are applied in tail-insertion order, meaning the last macro in the list
2837/// is the outermost macro.
2838///
2839/// # Usage
2840///
2841/// ```rust
2842/// use hyperlane::*;
2843/// use hyperlane_macros::*;
2844///
2845/// #[response_middleware(2)]
2846/// struct ResponseMiddleware2;
2847///
2848/// impl ServerHook for ResponseMiddleware2 {
2849///     async fn new(_ctx: &Context) -> Self {
2850///         Self
2851///     }
2852///
2853///     #[epilogue_macros(send, flush)]
2854///     async fn handle(self, ctx: &Context) {}
2855/// }
2856/// ```
2857#[proc_macro_attribute]
2858pub fn epilogue_macros(attr: TokenStream, item: TokenStream) -> TokenStream {
2859    epilogue_macros_macro(attr, item)
2860}
2861
2862/// Sends only the response body with data after function execution.
2863///
2864/// This attribute macro ensures that only the response body is automatically sent
2865/// to the client after the function completes, handling request headers separately,
2866/// with the specified data.
2867///
2868/// # Usage
2869///
2870/// ```rust
2871/// use hyperlane::*;
2872/// use hyperlane_macros::*;
2873///
2874/// #[route("/send_body_with_data")]
2875/// struct SendBodyWithData;
2876///
2877/// impl ServerHook for SendBodyWithData {
2878///     async fn new(_ctx: &Context) -> Self {
2879///         Self
2880///     }
2881///
2882///     #[epilogue_macros(send_body_with_data("Response body content"))]
2883///     async fn handle(self, ctx: &Context) {}
2884/// }
2885/// ```
2886///
2887/// The macro accepts data to send and should be applied to async functions
2888/// that accept a `&Context` parameter.
2889#[proc_macro_attribute]
2890pub fn send_body_with_data(attr: TokenStream, item: TokenStream) -> TokenStream {
2891    send_body_with_data_macro(attr, item, Position::Epilogue)
2892}
2893
2894/// Wraps function body with WebSocket stream processing.
2895///
2896/// This attribute macro generates code that wraps the function body with a check to see if
2897/// data can be read from a WebSocket stream. The function body is only executed
2898/// if data is successfully read from the stream.
2899///
2900/// This attribute macro generates code that wraps the function body with a check to see if
2901/// data can be read from a WebSocket stream. The function body is only executed
2902/// if data is successfully read from the stream.
2903///
2904/// # Arguments
2905///
2906/// - `TokenStream`: The buffer to read from the WebSocket stream.
2907/// - `TokenStream`: The function item to be modified
2908///
2909/// # Returns
2910///
2911/// Returns a TokenStream containing the modified function with WebSocket stream processing logic.
2912///
2913/// # Examples
2914///
2915/// Using no parameters (default buffer size):
2916/// ```rust
2917/// use hyperlane::*;
2918/// use hyperlane_macros::*;
2919///
2920/// #[route("/ws1")]
2921/// struct Websocket1;
2922///
2923/// impl ServerHook for Websocket1 {
2924///     async fn new(_ctx: &Context) -> Self {
2925///         Self
2926///     }
2927///
2928///     #[ws]
2929///     #[ws_from_stream]
2930///     async fn handle(self, ctx: &Context) {
2931///         let body: RequestBody = ctx.get_request_body().await;
2932///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
2933///         ctx.send_body_list_with_data(&body_list).await.unwrap();
2934///     }
2935/// }
2936/// ```
2937///
2938/// Using only buffer size:
2939/// ```rust
2940/// use hyperlane::*;
2941/// use hyperlane_macros::*;
2942///
2943/// #[route("/ws5")]
2944/// struct Websocket5;
2945///
2946/// impl ServerHook for Websocket5 {
2947///     async fn new(_ctx: &Context) -> Self {
2948///         Self
2949///     }
2950///
2951///     #[ws]
2952///     #[ws_from_stream(1024)]
2953///     async fn handle(self, ctx: &Context) {
2954///         let body: RequestBody = ctx.get_request_body().await;
2955///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
2956///         ctx.send_body_list_with_data(&body_list).await.unwrap();
2957///     }
2958/// }
2959/// ```
2960///
2961/// Using variable name to store request data:
2962/// ```rust
2963/// use hyperlane::*;
2964/// use hyperlane_macros::*;
2965///
2966/// #[route("/ws2")]
2967/// struct Websocket2;
2968///
2969/// impl ServerHook for Websocket2 {
2970///     async fn new(_ctx: &Context) -> Self {
2971///         Self
2972///     }
2973///
2974///     #[ws]
2975///     #[ws_from_stream(request)]
2976///     async fn handle(self, ctx: &Context) {
2977///         let body: &RequestBody = &request.get_body();
2978///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(body);
2979///         ctx.send_body_list_with_data(&body_list).await.unwrap();
2980///     }
2981/// }
2982/// ```
2983///
2984/// Using buffer size and variable name:
2985/// ```rust
2986/// use hyperlane::*;
2987/// use hyperlane_macros::*;
2988///
2989/// #[route("/ws3")]
2990/// struct Websocket3;
2991///
2992/// impl ServerHook for Websocket3 {
2993///     async fn new(_ctx: &Context) -> Self {
2994///         Self
2995///     }
2996///
2997///     #[ws]
2998///     #[ws_from_stream(1024, request)]
2999///     async fn handle(self, ctx: &Context) {
3000///         let body: &RequestBody = request.get_body();
3001///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
3002///         ctx.send_body_list_with_data(&body_list).await.unwrap();
3003///     }
3004/// }
3005/// ```
3006///
3007/// Using variable name and buffer size (reversed order):
3008/// ```rust
3009/// use hyperlane::*;
3010/// use hyperlane_macros::*;
3011///
3012/// #[route("/ws4")]
3013/// struct Websocket4;
3014///
3015/// impl ServerHook for Websocket4 {
3016///     async fn new(_ctx: &Context) -> Self {
3017///         Self
3018///     }
3019///
3020///     #[ws]
3021///     #[ws_from_stream(request, 1024)]
3022///     async fn handle(self, ctx: &Context) {
3023///         let body: &RequestBody = request.get_body();
3024///         let body_list: Vec<ResponseBody> = WebSocketFrame::create_frame_list(&body);
3025///         ctx.send_body_list_with_data(&body_list).await.unwrap();
3026///     }
3027/// }
3028///
3029/// impl Websocket4 {
3030///     #[ws_from_stream(request)]
3031///     async fn ws_from_stream_with_ref_self(&self, ctx: &Context) {}
3032/// }
3033///
3034/// #[ws_from_stream]
3035/// async fn standalone_ws_from_stream_handler(ctx: &Context) {}
3036/// ```
3037#[proc_macro_attribute]
3038pub fn ws_from_stream(attr: TokenStream, item: TokenStream) -> TokenStream {
3039    ws_from_stream_macro(attr, item)
3040}
3041
3042/// Wraps function body with HTTP stream processing.
3043///
3044/// This attribute macro generates code that wraps the function body with a check to see if
3045/// data can be read from an HTTP stream. The function body is only executed
3046/// if data is successfully read from the stream.
3047///
3048/// This attribute macro generates code that wraps the function body with a check to see if
3049/// data can be read from an HTTP stream. The function body is only executed
3050/// if data is successfully read from the stream.
3051///
3052/// # Arguments
3053///
3054/// - `TokenStream`: The buffer to read from the HTTP stream.
3055/// - `TokenStream`: The function item to be modified
3056///
3057/// # Returns
3058///
3059/// Returns a TokenStream containing the modified function with HTTP stream processing logic.
3060///
3061/// # Examples
3062///
3063/// Using with epilogue_macros:
3064/// ```rust
3065/// use hyperlane::*;
3066/// use hyperlane_macros::*;
3067///
3068/// #[route("/request_query")]
3069/// struct RequestQuery;
3070///
3071/// impl ServerHook for RequestQuery {
3072///     async fn new(_ctx: &Context) -> Self {
3073///         Self
3074///     }
3075///
3076///     #[epilogue_macros(
3077///         request_query("test" => request_query_option),
3078///         response_body(&format!("request query: {request_query_option:?}")),
3079///         send,
3080///         http_from_stream(1024)
3081///     )]
3082///     async fn handle(self, ctx: &Context) {}
3083/// }
3084/// ```
3085///
3086/// Using with variable name:
3087/// ```rust
3088/// use hyperlane::*;
3089/// use hyperlane_macros::*;
3090///
3091/// #[route("/http_from_stream")]
3092/// struct HttpFromStreamTest;
3093///
3094/// impl ServerHook for HttpFromStreamTest {
3095///     async fn new(_ctx: &Context) -> Self {
3096///         Self
3097///     }
3098///
3099///     #[epilogue_macros(
3100///         http_from_stream(_request)
3101///     )]
3102///     async fn handle(self, ctx: &Context) {}
3103/// }
3104///
3105/// impl HttpFromStreamTest {
3106///     #[http_from_stream(_request)]
3107///     async fn http_from_stream_with_ref_self(&self, ctx: &Context) {}
3108/// }
3109///
3110/// #[http_from_stream]
3111/// async fn standalone_http_from_stream_handler(ctx: &Context) {}
3112/// ```
3113#[proc_macro_attribute]
3114pub fn http_from_stream(attr: TokenStream, item: TokenStream) -> TokenStream {
3115    http_from_stream_macro(attr, item)
3116}