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