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