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 hook;
14mod host;
15mod http;
16mod hyperlane;
17mod protocol;
18mod referer;
19mod request;
20mod request_middleware;
21mod response;
22mod response_middleware;
23mod route;
24mod send;
25
26pub(crate) use aborted::*;
27pub(crate) use closed::*;
28pub(crate) use common::*;
29pub(crate) use filter::*;
30pub(crate) use flush::*;
31pub(crate) use hook::*;
32pub(crate) use host::*;
33pub(crate) use http::*;
34pub(crate) use hyperlane::*;
35pub(crate) use protocol::*;
36pub(crate) use referer::*;
37pub(crate) use request::*;
38pub(crate) use request_middleware::*;
39pub(crate) use response::*;
40pub(crate) use response_middleware::*;
41pub(crate) use route::*;
42pub(crate) use send::*;
43
44pub(crate) use proc_macro::TokenStream;
45pub(crate) use proc_macro2::TokenStream as TokenStream2;
46pub(crate) use quote::quote;
47pub(crate) use syn::{
48    Ident, Token,
49    parse::{Parse, ParseStream, Result},
50    punctuated::Punctuated,
51    *,
52};
53
54/// Restricts function execution to HTTP GET requests only.
55///
56/// This attribute macro ensures the decorated function only executes when the incoming request
57/// uses the GET HTTP method. Requests with other methods will be filtered out.
58///
59/// # Usage
60///
61/// ```rust
62/// use hyperlane::*;
63/// use hyperlane_macros::*;
64///
65/// #[get]
66/// async fn handle_get(ctx: Context) {
67///     // Function body
68/// }
69/// ```
70///
71/// The macro takes no parameters and should be applied directly to async functions
72/// that accept a `Context` parameter.
73#[proc_macro_attribute]
74pub fn get(_attr: TokenStream, item: TokenStream) -> TokenStream {
75    get_handler(item)
76}
77
78/// Restricts function execution to HTTP POST requests only.
79///
80/// This attribute macro ensures the decorated function only executes when the incoming request
81/// uses the POST HTTP method. Requests with other methods will be filtered out.
82///
83/// # Usage
84///
85/// ```rust
86/// use hyperlane::*;
87/// use hyperlane_macros::*;
88///
89/// #[post]
90/// async fn handle_post(ctx: Context) {
91///     // Function body
92/// }
93/// ```
94///
95/// The macro takes no parameters and should be applied directly to async functions
96/// that accept a `Context` parameter.
97#[proc_macro_attribute]
98pub fn post(_attr: TokenStream, item: TokenStream) -> TokenStream {
99    post_handler(item)
100}
101
102/// Restricts function execution to HTTP PUT requests only.
103///
104/// This attribute macro ensures the decorated function only executes when the incoming request
105/// uses the PUT HTTP method. Requests with other methods will be filtered out.
106///
107/// # Usage
108///
109/// ```rust
110/// use hyperlane::*;
111/// use hyperlane_macros::*;
112///
113/// #[put]
114/// async fn handle_put(ctx: Context) {
115///     // Function body
116/// }
117/// ```
118///
119/// The macro takes no parameters and should be applied directly to async functions
120/// that accept a `Context` parameter.
121#[proc_macro_attribute]
122pub fn put(_attr: TokenStream, item: TokenStream) -> TokenStream {
123    put_handler(item)
124}
125
126/// Restricts function execution to HTTP DELETE requests only.
127///
128/// This attribute macro ensures the decorated function only executes when the incoming request
129/// uses the DELETE HTTP method. Requests with other methods will be filtered out.
130///
131/// # Usage
132///
133/// ```rust
134/// use hyperlane::*;
135/// use hyperlane_macros::*;
136///
137/// #[delete]
138/// async fn handle_delete(ctx: Context) {
139///     // Function body
140/// }
141/// ```
142///
143/// The macro takes no parameters and should be applied directly to async functions
144/// that accept a `Context` parameter.
145#[proc_macro_attribute]
146pub fn delete(_attr: TokenStream, item: TokenStream) -> TokenStream {
147    delete_handler(item)
148}
149
150/// Restricts function execution to HTTP PATCH requests only.
151///
152/// This attribute macro ensures the decorated function only executes when the incoming request
153/// uses the PATCH HTTP method. Requests with other methods will be filtered out.
154///
155/// # Usage
156///
157/// ```rust
158/// use hyperlane::*;
159/// use hyperlane_macros::*;
160///
161/// #[patch]
162/// async fn handle_patch(ctx: Context) {
163///     // Function body
164/// }
165/// ```
166///
167/// The macro takes no parameters and should be applied directly to async functions
168/// that accept a `Context` parameter.
169#[proc_macro_attribute]
170pub fn patch(_attr: TokenStream, item: TokenStream) -> TokenStream {
171    patch_handler(item)
172}
173
174/// Restricts function execution to HTTP HEAD requests only.
175///
176/// This attribute macro ensures the decorated function only executes when the incoming request
177/// uses the HEAD HTTP method. Requests with other methods will be filtered out.
178///
179/// # Usage
180///
181/// ```rust
182/// use hyperlane::*;
183/// use hyperlane_macros::*;
184///
185/// #[head]
186/// async fn handle_head(ctx: Context) {
187///     // Function body
188/// }
189/// ```
190///
191/// The macro takes no parameters and should be applied directly to async functions
192/// that accept a `Context` parameter.
193#[proc_macro_attribute]
194pub fn head(_attr: TokenStream, item: TokenStream) -> TokenStream {
195    head_handler(item)
196}
197
198/// Restricts function execution to HTTP OPTIONS requests only.
199///
200/// This attribute macro ensures the decorated function only executes when the incoming request
201/// uses the OPTIONS HTTP method. Requests with other methods will be filtered out.
202///
203/// # Usage
204///
205/// ```rust
206/// use hyperlane::*;
207/// use hyperlane_macros::*;
208///
209/// #[options]
210/// async fn handle_options(ctx: Context) {
211///     // Function body
212/// }
213/// ```
214///
215/// The macro takes no parameters and should be applied directly to async functions
216/// that accept a `Context` parameter.
217#[proc_macro_attribute]
218pub fn options(_attr: TokenStream, item: TokenStream) -> TokenStream {
219    options_handler(item)
220}
221
222/// Restricts function execution to HTTP CONNECT requests only.
223///
224/// This attribute macro ensures the decorated function only executes when the incoming request
225/// uses the CONNECT HTTP method. Requests with other methods will be filtered out.
226///
227/// # Usage
228///
229/// ```rust
230/// use hyperlane::*;
231/// use hyperlane_macros::*;
232///
233/// #[connect]
234/// async fn handle_connect(ctx: Context) {
235///     // Function body
236/// }
237/// ```
238///
239/// The macro takes no parameters and should be applied directly to async functions
240/// that accept a `Context` parameter.
241#[proc_macro_attribute]
242pub fn connect(_attr: TokenStream, item: TokenStream) -> TokenStream {
243    connect_handler(item)
244}
245
246/// Restricts function execution to HTTP TRACE requests only.
247///
248/// This attribute macro ensures the decorated function only executes when the incoming request
249/// uses the TRACE HTTP method. Requests with other methods will be filtered out.
250///
251/// # Usage
252///
253/// ```rust
254/// use hyperlane::*;
255/// use hyperlane_macros::*;
256///
257/// #[trace]
258/// async fn handle_trace(ctx: Context) {
259///     // Function body
260/// }
261/// ```
262///
263/// The macro takes no parameters and should be applied directly to async functions
264/// that accept a `Context` parameter.
265#[proc_macro_attribute]
266pub fn trace(_attr: TokenStream, item: TokenStream) -> TokenStream {
267    trace_handler(item)
268}
269
270/// Allows function to handle multiple HTTP methods.
271///
272/// This attribute macro configures the decorated function to execute for any of the specified
273/// HTTP methods. Methods should be provided as a comma-separated list.
274///
275/// # Usage
276///
277/// ```rust
278/// use hyperlane::*;
279/// use hyperlane_macros::*;
280///
281/// #[methods(get, post)]
282/// async fn handle_get_post(ctx: Context) {
283///     // Function body
284/// }
285///
286/// #[methods(put, patch, delete)]
287/// async fn handle_modifications(ctx: Context) {
288///     // Function body
289/// }
290/// ```
291///
292/// The macro accepts a comma-separated list of HTTP method names (lowercase) and should be
293/// applied to async functions that accept a `Context` parameter.
294#[proc_macro_attribute]
295pub fn methods(attr: TokenStream, item: TokenStream) -> TokenStream {
296    methods_macro(attr, item)
297}
298
299/// Restricts function execution to WebSocket upgrade requests only.
300///
301/// This attribute macro ensures the decorated function only executes when the incoming request
302/// is a valid WebSocket upgrade request with proper request headers and protocol negotiation.
303///
304/// # Usage
305///
306/// ```rust
307/// use hyperlane::*;
308/// use hyperlane_macros::*;
309///
310/// #[ws]
311/// async fn handle_websocket(ctx: Context) {
312///     // WebSocket handling logic
313/// }
314/// ```
315///
316/// The macro takes no parameters and should be applied directly to async functions
317/// that accept a `Context` parameter.
318#[proc_macro_attribute]
319pub fn ws(_attr: TokenStream, item: TokenStream) -> TokenStream {
320    ws_macro(item)
321}
322
323/// Restricts function execution to standard HTTP requests only.
324///
325/// This attribute macro ensures the decorated function only executes for standard HTTP requests,
326/// excluding WebSocket upgrades and other protocol upgrade requests.
327///
328/// # Usage
329///
330/// ```rust
331/// use hyperlane::*;
332/// use hyperlane_macros::*;
333///
334/// #[http]
335/// async fn handle_http(ctx: Context) {
336///     // HTTP request handling logic
337/// }
338/// ```
339///
340/// The macro takes no parameters and should be applied directly to async functions
341/// that accept a `Context` parameter.
342#[proc_macro_attribute]
343pub fn http(_attr: TokenStream, item: TokenStream) -> TokenStream {
344    http_macro(item)
345}
346
347/// Sets the HTTP status code for the response.
348///
349/// This attribute macro configures the HTTP status code that will be sent with the response.
350/// The status code can be provided as a numeric literal or a global constant.
351///
352/// # Usage
353///
354/// ```rust
355/// use hyperlane::*;
356/// use hyperlane_macros::*;
357///
358/// const CUSTOM_STATUS: i32 = 418;
359///
360/// #[response_status_code(200)]
361/// async fn success_handler(ctx: Context) {
362///     // Response will have status code 200
363/// }
364///
365/// #[response_status_code(404)]
366/// async fn not_found_handler(ctx: Context) {
367///     // Response will have status code 404
368/// }
369///
370/// #[response_status_code(CUSTOM_STATUS)]
371/// async fn custom_handler(ctx: Context) {
372///     // Response will have status code from global constant
373/// }
374/// ```
375///
376/// The macro accepts a numeric HTTP status code or a global constant
377/// and should be applied to async functions that accept a `Context` parameter.
378#[proc_macro_attribute]
379pub fn response_status_code(attr: TokenStream, item: TokenStream) -> TokenStream {
380    response_status_code_macro(attr, item)
381}
382
383/// Sets the HTTP reason phrase for the response.
384///
385/// This attribute macro configures the HTTP reason phrase that accompanies the status code.
386/// The reason phrase can be provided as a string literal or a global constant.
387///
388/// # Usage
389///
390/// ```rust
391/// use hyperlane::*;
392/// use hyperlane_macros::*;
393///
394/// const CUSTOM_REASON: &str = "I'm a teapot";
395///
396/// #[response_reason_phrase("OK")]
397/// async fn success_handler(ctx: Context) {
398///     // Response will have reason phrase "OK"
399/// }
400///
401/// #[response_reason_phrase("Not Found")]
402/// async fn not_found_handler(ctx: Context) {
403///     // Response will have reason phrase "Not Found"
404/// }
405///
406/// #[response_reason_phrase(CUSTOM_REASON)]
407/// async fn custom_handler(ctx: Context) {
408///     // Response will have reason phrase from global constant
409/// }
410/// ```
411///
412/// The macro accepts a string literal or global constant for the reason phrase and should be
413/// applied to async functions that accept a `Context` parameter.
414#[proc_macro_attribute]
415pub fn response_reason_phrase(attr: TokenStream, item: TokenStream) -> TokenStream {
416    response_reason_phrase_macro(attr, item)
417}
418
419/// Sets or replaces a specific HTTP response header.
420///
421/// This attribute macro configures a specific HTTP response header that will be sent with the response.
422/// Both the header name and value can be provided as string literals or global constants.
423/// Use `"key", "value"` to set a header (add to existing headers) or `"key" => "value"` to replace a header (overwrite existing).
424///
425/// # Usage
426///
427/// ```rust
428/// use hyperlane::*;
429/// use hyperlane_macros::*;
430///
431/// const HEADER_NAME: &str = "X-Custom-Header";
432/// const HEADER_VALUE: &str = "custom-value";
433///
434/// #[response_header("Content-Type", "application/json")]
435/// async fn json_handler(ctx: Context) {
436///     // Response will have Content-Type header set to application/json
437/// }
438///
439/// #[response_header("X-Static-Header" => "static-value")]
440/// async fn set_header_handler(ctx: Context) {
441///     // Response will have static header replaced (overwrite existing)
442/// }
443///
444/// #[response_header(HEADER_NAME, HEADER_VALUE)]
445/// async fn dynamic_header_handler(ctx: Context) {
446///     // Response will have header from global constants
447/// }
448///
449/// #[response_header("Cache-Control" => "no-cache")]
450/// async fn set_cache_handler(ctx: Context) {
451///     // Response will have Cache-Control header replaced
452/// }
453///
454/// #[response_header("X-Add-Header", "add-value")]
455/// #[response_header("X-Set-Header" => "set-value")]
456/// async fn header_operations_handler(ctx: Context) {
457///     // Response will have X-Add-Header set and X-Set-Header replaced
458/// }
459/// ```
460///
461/// The macro accepts header name and header value, both can be string literals or global constants.
462/// Use `"key", "value"` for setting headers and `"key" => "value"` for replacing headers.
463/// Should be applied to async functions that accept a `Context` parameter.
464#[proc_macro_attribute]
465pub fn response_header(attr: TokenStream, item: TokenStream) -> TokenStream {
466    response_header_macro(attr, item)
467}
468
469/// Sets the HTTP response body.
470///
471/// This attribute macro configures the HTTP response body that will be sent with the response.
472/// The body content can be provided as a string literal or a global constant.
473///
474/// # Usage
475///
476/// ```rust
477/// use hyperlane::*;
478/// use hyperlane_macros::*;
479///
480/// const RESPONSE_DATA: &str = "Dynamic content from constant";
481///
482/// #[response_body("Hello, World!")]
483/// async fn hello_handler(ctx: Context) {
484///     // Response will have body "Hello, World!"
485/// }
486///
487/// #[response_body("{\"message\": \"success\"}")]
488/// async fn json_response_handler(ctx: Context) {
489///     // Response will have JSON body
490/// }
491///
492/// #[response_body(RESPONSE_DATA)]
493/// async fn dynamic_body_handler(ctx: Context) {
494///     // Response will have body from global constant
495/// }
496/// ```
497///
498/// The macro accepts a string literal or global constant for the response body and should be
499/// applied to async functions that accept a `Context` parameter.
500#[proc_macro_attribute]
501pub fn response_body(attr: TokenStream, item: TokenStream) -> TokenStream {
502    response_body_macro(attr, item)
503}
504
505/// Sets the HTTP response version.
506///
507/// This attribute macro configures the HTTP response version that will be sent with the response.
508/// The version can be provided as a variable or code block.
509///
510/// # Usage
511///
512/// ```rust
513/// use hyperlane::*;
514/// use hyperlane_macros::*;
515///
516/// #[response_version(HttpVersion::HTTP1_1)]
517/// async fn version_from_constant(ctx: Context) {
518///     // Response will have version from global constant
519/// }
520/// ```
521///
522/// The macro accepts a variable or code block for the response version and should be
523/// applied to async functions that accept a `Context` parameter.
524#[proc_macro_attribute]
525pub fn response_version(attr: TokenStream, item: TokenStream) -> TokenStream {
526    response_version_macro(attr, item)
527}
528
529/// Automatically sends the complete response after function execution.
530///
531/// This attribute macro ensures that the response (request headers and body) is automatically sent
532/// to the client after the function completes execution.
533///
534/// # Usage
535///
536/// ```rust
537/// use hyperlane::*;
538/// use hyperlane_macros::*;
539///
540/// #[send]
541/// async fn auto_send_handler(ctx: Context) {
542///     let _ = ctx.set_response_body("Hello World").await;
543///     // Response is automatically sent after function returns
544/// }
545/// ```
546///
547/// The macro takes no parameters and should be applied directly to async functions
548/// that accept a `Context` parameter.
549#[proc_macro_attribute]
550pub fn send(_attr: TokenStream, item: TokenStream) -> TokenStream {
551    send_macro(item)
552}
553
554/// Automatically sends only the response body after function execution.
555///
556/// This attribute macro ensures that only the response body is automatically sent
557/// to the client after the function completes, handling request headers separately.
558///
559/// # Usage
560///
561/// ```rust
562/// use hyperlane::*;
563/// use hyperlane_macros::*;
564///
565/// #[send_body]
566/// async fn auto_send_body_handler(ctx: Context) {
567///     let _ = ctx.set_response_body("Response body content").await;
568///     // Only response body is automatically sent after function returns
569/// }
570/// ```
571///
572/// The macro takes no parameters and should be applied directly to async functions
573/// that accept a `Context` parameter.
574#[proc_macro_attribute]
575pub fn send_body(_attr: TokenStream, item: TokenStream) -> TokenStream {
576    send_body_macro(item)
577}
578
579/// Sends the complete response exactly once after function execution.
580///
581/// This attribute macro ensures that the response is sent exactly once to the client,
582/// preventing multiple response transmissions for single-use scenarios.
583///
584/// # Usage
585///
586/// ```rust
587/// use hyperlane::*;
588/// use hyperlane_macros::*;
589///
590/// #[send_once]
591/// async fn send_once_handler(ctx: Context) {
592///     let _ = ctx.set_response_body("One-time response").await;
593///     // Response is sent exactly once after function returns
594/// }
595/// ```
596///
597/// The macro takes no parameters and should be applied directly to async functions
598/// that accept a `Context` parameter.
599#[proc_macro_attribute]
600pub fn send_once(_attr: TokenStream, item: TokenStream) -> TokenStream {
601    send_once_macro(item)
602}
603
604/// Sends only the response body exactly once after function execution.
605///
606/// This attribute macro ensures that the response body is sent exactly once to the client,
607/// preventing multiple body transmissions for single-use scenarios.
608///
609/// # Usage
610///
611/// ```rust
612/// use hyperlane::*;
613/// use hyperlane_macros::*;
614///
615/// #[send_once_body]
616/// async fn send_once_body_handler(ctx: Context) {
617///     let _ = ctx.set_response_body("One-time body content").await;
618///     // Response body is sent exactly once after function returns
619/// }
620/// ```
621///
622/// The macro takes no parameters and should be applied directly to async functions
623/// that accept a `Context` parameter.
624#[proc_macro_attribute]
625pub fn send_once_body(_attr: TokenStream, item: TokenStream) -> TokenStream {
626    send_once_body_macro(item)
627}
628
629/// Flushes the response stream after function execution.
630///
631/// This attribute macro ensures that the response stream is flushed to guarantee immediate
632/// data transmission, forcing any buffered response data to be sent to the client.
633///
634/// # Usage
635///
636/// ```rust
637/// use hyperlane::*;
638/// use hyperlane_macros::*;
639///
640/// #[flush]
641/// async fn flush_handler(ctx: Context) {
642///     let _ = ctx.set_response_body("Immediate response").await;
643///     // Response stream is flushed after function returns
644/// }
645/// ```
646///
647/// The macro takes no parameters and should be applied directly to async functions
648/// that accept a `Context` parameter.
649#[proc_macro_attribute]
650pub fn flush(_attr: TokenStream, item: TokenStream) -> TokenStream {
651    flush_macro(item)
652}
653
654/// Handles aborted request scenarios.
655///
656/// This attribute macro configures the function to handle cases where the client has
657/// aborted the request, providing appropriate handling for interrupted or cancelled requests.
658///
659/// # Usage
660///
661/// ```rust
662/// use hyperlane::*;
663/// use hyperlane_macros::*;
664///
665/// #[aborted]
666/// async fn handle_aborted(ctx: Context) {
667///     // Handle aborted request logic
668/// }
669/// ```
670///
671/// The macro takes no parameters and should be applied directly to async functions
672/// that accept a `Context` parameter.
673#[proc_macro_attribute]
674pub fn aborted(_attr: TokenStream, item: TokenStream) -> TokenStream {
675    aborted_macro(item)
676}
677
678/// Handles closed connection scenarios.
679///
680/// This attribute macro configures the function to handle cases where the connection
681/// has been closed, providing appropriate handling for terminated or disconnected connections.
682///
683/// # Usage
684///
685/// ```rust
686/// use hyperlane::*;
687/// use hyperlane_macros::*;
688///
689/// #[closed]
690/// async fn handle_closed(ctx: Context) {
691///     // Handle closed connection logic
692/// }
693/// ```
694///
695/// The macro takes no parameters and should be applied directly to async functions
696/// that accept a `Context` parameter.
697#[proc_macro_attribute]
698pub fn closed(_attr: TokenStream, item: TokenStream) -> TokenStream {
699    closed_macro(item)
700}
701
702/// Restricts function execution to HTTP/2 Cleartext (h2c) requests only.
703///
704/// This attribute macro ensures the decorated function only executes for HTTP/2 cleartext
705/// requests that use the h2c upgrade mechanism.
706///
707/// # Usage
708///
709/// ```rust
710/// use hyperlane::*;
711/// use hyperlane_macros::*;
712///
713/// #[h2c]
714/// async fn handle_h2c(ctx: Context) {
715///     // Handle HTTP/2 cleartext requests
716/// }
717/// ```
718///
719/// The macro takes no parameters and should be applied directly to async functions
720/// that accept a `Context` parameter.
721#[proc_macro_attribute]
722pub fn h2c(_attr: TokenStream, item: TokenStream) -> TokenStream {
723    h2c_macro(item)
724}
725
726/// Restricts function execution to HTTP/0.9 requests only.
727///
728/// This attribute macro ensures the decorated function only executes for HTTP/0.9
729/// protocol requests, the earliest version of the HTTP protocol.
730///
731/// # Usage
732///
733/// ```rust
734/// use hyperlane::*;
735/// use hyperlane_macros::*;
736///
737/// #[http0_9]
738/// async fn handle_http09(ctx: Context) {
739///     // Handle HTTP/0.9 requests
740/// }
741/// ```
742///
743/// The macro takes no parameters and should be applied directly to async functions
744/// that accept a `Context` parameter.
745#[proc_macro_attribute]
746pub fn http0_9(_attr: TokenStream, item: TokenStream) -> TokenStream {
747    http0_9_macro(item)
748}
749
750/// Restricts function execution to HTTP/1.0 requests only.
751///
752/// This attribute macro ensures the decorated function only executes for HTTP/1.0
753/// protocol requests.
754///
755/// # Usage
756///
757/// ```rust
758/// use hyperlane::*;
759/// use hyperlane_macros::*;
760///
761/// #[http1_0]
762/// async fn handle_http10(ctx: Context) {
763///     // Handle HTTP/1.0 requests
764/// }
765/// ```
766///
767/// The macro takes no parameters and should be applied directly to async functions
768/// that accept a `Context` parameter.
769#[proc_macro_attribute]
770pub fn http1_0(_attr: TokenStream, item: TokenStream) -> TokenStream {
771    http1_0_macro(item)
772}
773
774/// Restricts function execution to HTTP/1.1 requests only.
775///
776/// This attribute macro ensures the decorated function only executes for HTTP/1.1
777/// protocol requests.
778///
779/// # Usage
780///
781/// ```rust
782/// use hyperlane::*;
783/// use hyperlane_macros::*;
784///
785/// #[http1_1]
786/// async fn handle_http11(ctx: Context) {
787///     // Handle HTTP/1.1 requests
788/// }
789/// ```
790///
791/// The macro takes no parameters and should be applied directly to async functions
792/// that accept a `Context` parameter.
793#[proc_macro_attribute]
794pub fn http1_1(_attr: TokenStream, item: TokenStream) -> TokenStream {
795    http1_1_macro(item)
796}
797
798/// Restricts function execution to HTTP/1.1 or higher protocol versions.
799///
800/// This attribute macro ensures the decorated function only executes for HTTP/1.1
801/// or newer protocol versions, including HTTP/2, HTTP/3, and future versions.
802///
803/// # Usage
804///
805/// ```rust
806/// use hyperlane::*;
807/// use hyperlane_macros::*;
808///
809/// #[http1_1_or_higher]
810/// async fn handle_modern_http(ctx: Context) {
811///     // Handle HTTP/1.1, HTTP/2, HTTP/3, etc.
812/// }
813/// ```
814///
815/// The macro takes no parameters and should be applied directly to async functions
816/// that accept a `Context` parameter.
817#[proc_macro_attribute]
818pub fn http1_1_or_higher(_attr: TokenStream, item: TokenStream) -> TokenStream {
819    http1_1_or_higher_macro(item)
820}
821
822/// Restricts function execution to HTTP/2 requests only.
823///
824/// This attribute macro ensures the decorated function only executes for HTTP/2
825/// protocol requests.
826///
827/// # Usage
828///
829/// ```rust
830/// use hyperlane::*;
831/// use hyperlane_macros::*;
832///
833/// #[http2]
834/// async fn handle_http2(ctx: Context) {
835///     // Handle HTTP/2 requests
836/// }
837/// ```
838///
839/// The macro takes no parameters and should be applied directly to async functions
840/// that accept a `Context` parameter.
841#[proc_macro_attribute]
842pub fn http2(_attr: TokenStream, item: TokenStream) -> TokenStream {
843    http2_macro(item)
844}
845
846/// Restricts function execution to HTTP/3 requests only.
847///
848/// This attribute macro ensures the decorated function only executes for HTTP/3
849/// protocol requests, the latest version of the HTTP protocol.
850///
851/// # Usage
852///
853/// ```rust
854/// use hyperlane::*;
855/// use hyperlane_macros::*;
856///
857/// #[http3]
858/// async fn handle_http3(ctx: Context) {
859///     // Handle HTTP/3 requests
860/// }
861/// ```
862///
863/// The macro takes no parameters and should be applied directly to async functions
864/// that accept a `Context` parameter.
865#[proc_macro_attribute]
866pub fn http3(_attr: TokenStream, item: TokenStream) -> TokenStream {
867    http3_macro(item)
868}
869
870/// Restricts function execution to TLS-encrypted requests only.
871///
872/// This attribute macro ensures the decorated function only executes for requests
873/// that use TLS/SSL encryption on the connection.
874///
875/// # Usage
876///
877/// ```rust
878/// use hyperlane::*;
879/// use hyperlane_macros::*;
880///
881/// #[tls]
882/// async fn handle_secure(ctx: Context) {
883///     // Handle TLS-encrypted requests only
884/// }
885/// ```
886///
887/// The macro takes no parameters and should be applied directly to async functions
888/// that accept a `Context` parameter.
889#[proc_macro_attribute]
890pub fn tls(_attr: TokenStream, item: TokenStream) -> TokenStream {
891    tls_macro(item)
892}
893
894/// Handles requests with unknown or non-standard HTTP methods.
895///
896/// This attribute macro configures the function to handle requests that use
897/// unrecognized or unsupported HTTP methods, providing a fallback for non-standard methods.
898///
899/// # Usage
900///
901/// ```rust
902/// use hyperlane::*;
903/// use hyperlane_macros::*;
904///
905/// #[filter_unknown_method]
906/// async fn handle_unknown_method(ctx: Context) {
907///     // Handle requests with unknown HTTP methods
908/// }
909/// ```
910///
911/// The macro takes no parameters and should be applied directly to async functions
912/// that accept a `Context` parameter.
913#[proc_macro_attribute]
914pub fn filter_unknown_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
915    filter_unknown_method_macro(item)
916}
917
918/// Handles requests with unknown or non-standard upgrade protocols.
919///
920/// This attribute macro configures the function to handle requests that specify
921/// unrecognized upgrade protocols, providing a fallback for non-standard upgrade request headers.
922///
923/// # Usage
924///
925/// ```rust
926/// use hyperlane::*;
927/// use hyperlane_macros::*;
928///
929/// #[filter_unknown_upgrade]
930/// async fn handle_unknown_upgrade(ctx: Context) {
931///     // Handle requests with unknown upgrade protocols
932/// }
933/// ```
934///
935/// The macro takes no parameters and should be applied directly to async functions
936/// that accept a `Context` parameter.
937#[proc_macro_attribute]
938pub fn filter_unknown_upgrade(_attr: TokenStream, item: TokenStream) -> TokenStream {
939    filter_unknown_upgrade_macro(item)
940}
941
942/// Handles requests with unknown or non-standard HTTP versions.
943///
944/// This attribute macro configures the function to handle requests that use
945/// unrecognized HTTP protocol versions, providing a fallback for non-standard versions.
946///
947/// # Usage
948///
949/// ```rust
950/// use hyperlane::*;
951/// use hyperlane_macros::*;
952///
953/// #[filter_unknown_version]
954/// async fn handle_unknown_version(ctx: Context) {
955///     // Handle requests with unknown HTTP versions
956/// }
957/// ```
958///
959/// The macro takes no parameters and should be applied directly to async functions
960/// that accept a `Context` parameter.
961#[proc_macro_attribute]
962pub fn filter_unknown_version(_attr: TokenStream, item: TokenStream) -> TokenStream {
963    filter_unknown_version_macro(item)
964}
965
966/// Handles requests with any unknown characteristics.
967///
968/// This attribute macro combines filtering for unknown methods, upgrade protocols, and HTTP versions,
969/// providing comprehensive handling for requests with any unrecognized characteristics.
970///
971/// # Usage
972///
973/// ```rust
974/// use hyperlane::*;
975/// use hyperlane_macros::*;
976///
977/// #[filter_unknown]
978/// async fn handle_all_unknown(ctx: Context) {
979///     // Handle requests with any unknown characteristics
980/// }
981/// ```
982///
983/// The macro takes no parameters and should be applied directly to async functions
984/// that accept a `Context` parameter.
985#[proc_macro_attribute]
986pub fn filter_unknown(_attr: TokenStream, item: TokenStream) -> TokenStream {
987    filter_unknown_macro(item)
988}
989
990/// Restricts function execution to requests with a specific host.
991///
992/// This attribute macro ensures the decorated function only executes when the incoming request
993/// has a host header that matches the specified value. Requests with different or missing host headers will be filtered out.
994///
995/// # Usage
996///
997/// ```rust
998/// use hyperlane::*;
999/// use hyperlane_macros::*;
1000///
1001/// #[host("localhost")]
1002/// async fn handle_example_com(ctx: Context) {
1003///     // Function body for localhost requests
1004/// }
1005///
1006/// #[host("api.localhost")]
1007/// async fn handle_api_subdomain(ctx: Context) {
1008///     // Function body for api.localhost requests
1009/// }
1010/// ```
1011///
1012/// The macro accepts a string literal specifying the expected host value and should be
1013/// applied to async functions that accept a `Context` parameter.
1014#[proc_macro_attribute]
1015pub fn host(attr: TokenStream, item: TokenStream) -> TokenStream {
1016    host_macro(attr, item)
1017}
1018
1019/// Filters requests that have no host header.
1020///
1021/// This attribute macro ensures the decorated function only executes when the incoming request
1022/// has a host header present. Requests without a host header will be filtered out.
1023///
1024/// # Usage
1025///
1026/// ```rust
1027/// use hyperlane::*;
1028/// use hyperlane_macros::*;
1029///
1030/// #[host_filter("localhost")]
1031/// async fn handle_with_host(ctx: Context) {
1032///     // Function body for requests with host header
1033/// }
1034/// ```
1035///
1036/// The macro takes no parameters and should be applied directly to async functions
1037/// that accept a `Context` parameter.
1038#[proc_macro_attribute]
1039pub fn host_filter(attr: TokenStream, item: TokenStream) -> TokenStream {
1040    host_filter_macro(attr, item)
1041}
1042
1043/// Restricts function execution to requests with a specific referer.
1044///
1045/// This attribute macro ensures the decorated function only executes when the incoming request
1046/// has a referer header that matches the specified value. Requests with different or missing referer headers will be filtered out.
1047///
1048/// # Usage
1049///
1050/// ```rust
1051/// use hyperlane::*;
1052/// use hyperlane_macros::*;
1053///
1054/// #[referer("http://localhost")]
1055/// async fn handle_example_referer(ctx: Context) {
1056///     // Function body for requests from localhost
1057/// }
1058///
1059/// #[referer("https://api.localhost")]
1060/// async fn handle_api_referer(ctx: Context) {
1061///     // Function body for requests from api.localhost
1062/// }
1063/// ```
1064///
1065/// The macro accepts a string literal specifying the expected referer value and should be
1066/// applied to async functions that accept a `Context` parameter.
1067#[proc_macro_attribute]
1068pub fn referer(attr: TokenStream, item: TokenStream) -> TokenStream {
1069    referer_macro(attr, item)
1070}
1071
1072/// Filters requests that have a specific referer header.
1073///
1074/// This attribute macro ensures the decorated function only executes when the incoming request
1075/// does not have a referer header that matches the specified value. Requests with the matching referer header will be filtered out.
1076///
1077/// # Usage
1078///
1079/// ```rust
1080/// use hyperlane::*;
1081/// use hyperlane_macros::*;
1082///
1083/// #[referer_filter("http://localhost")]
1084/// async fn handle_without_spam_referer(ctx: Context) {
1085///     // Function body for requests not from localhost
1086/// }
1087/// ```
1088///
1089/// The macro accepts a string literal specifying the referer value to filter out and should be
1090/// applied to async functions that accept a `Context` parameter.
1091#[proc_macro_attribute]
1092pub fn referer_filter(attr: TokenStream, item: TokenStream) -> TokenStream {
1093    referer_filter_macro(attr, item)
1094}
1095
1096/// Executes a specified function before the main handler function.
1097///
1098/// This attribute macro configures a pre-execution hook that runs before the main function logic.
1099/// The specified hook function will be called first, followed by the main function execution.
1100///
1101/// # Usage
1102///
1103/// ```rust
1104/// use hyperlane::*;
1105/// use hyperlane_macros::*;
1106///
1107/// #[get]
1108/// async fn pre_handler(ctx: Context) {
1109///     // Pre-execution logic
1110/// }
1111///
1112/// #[pre_hook(pre_handler)]
1113/// async fn main_handler(ctx: Context) {
1114///     // Main function logic (runs after pre_handler)
1115/// }
1116/// ```
1117///
1118/// The macro accepts a function name as parameter. Both the hook function and main function
1119/// must accept a `Context` parameter. Avoid combining this macro with other macros on the
1120/// same function to prevent macro expansion conflicts.
1121#[proc_macro_attribute]
1122pub fn pre_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1123    pre_hook_macro(attr, item)
1124}
1125
1126/// Executes a specified function after the main handler function.
1127///
1128/// This attribute macro configures a post-execution hook that runs after the main function logic.
1129/// The main function will execute first, followed by the specified hook function.
1130///
1131/// # Usage
1132///
1133/// ```rust
1134/// use hyperlane::*;
1135/// use hyperlane_macros::*;
1136///
1137/// #[send]
1138/// async fn post_handler(ctx: Context) {
1139///     // Post-execution logic
1140/// }
1141///
1142/// #[post_hook(post_handler)]
1143/// async fn main_handler(ctx: Context) {
1144///     // Main function logic (runs before post_handler)
1145/// }
1146/// ```
1147///
1148/// The macro accepts a function name as parameter. Both the hook function and main function
1149/// must accept a `Context` parameter. Avoid combining this macro with other macros on the
1150/// same function to prevent macro expansion conflicts.
1151#[proc_macro_attribute]
1152pub fn post_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1153    post_hook_macro(attr, item)
1154}
1155
1156/// Extracts the raw request body into a specified variable.
1157///
1158/// This attribute macro extracts the raw request body content into a variable
1159/// with the fixed type `RequestBody`. The body content is not parsed or deserialized.
1160///
1161/// # Usage
1162///
1163/// ```rust
1164/// use hyperlane::*;
1165/// use hyperlane_macros::*;
1166///
1167/// #[request_body(raw_body)]
1168/// async fn handle_raw_body(ctx: Context) {
1169///     // Use the raw request body
1170///     let body_content = raw_body;
1171/// }
1172/// ```
1173///
1174/// The macro accepts only a variable name. The variable will be available
1175/// in the function scope as a `RequestBody` type.
1176#[proc_macro_attribute]
1177pub fn request_body(attr: TokenStream, item: TokenStream) -> TokenStream {
1178    request_body_macro(attr, item)
1179}
1180
1181/// Parses the request body as JSON into a specified variable and type.
1182///
1183/// This attribute macro extracts and deserializes the request body content as JSON into a variable
1184/// with the specified type. The body content is parsed as JSON using serde.
1185///
1186/// # Usage
1187///
1188/// ```rust
1189/// use hyperlane::*;
1190/// use hyperlane_macros::*;
1191/// use serde::Deserialize;
1192///
1193/// #[derive(Deserialize, Clone)]
1194/// struct UserData {
1195///     name: String,
1196///     age: u32,
1197/// }
1198///
1199/// #[request_body_json(user_data: UserData)]
1200/// async fn handle_user(ctx: Context) {
1201///     if let Ok(data) = user_data {
1202///         // Use the parsed user data
1203///     }
1204/// }
1205/// ```
1206///
1207/// The macro accepts a variable name and type in the format `variable_name: Type`.
1208/// The variable will be available in the function scope as a `Result<Type, JsonError>`.
1209#[proc_macro_attribute]
1210pub fn request_body_json(attr: TokenStream, item: TokenStream) -> TokenStream {
1211    request_body_json_macro(attr, item)
1212}
1213
1214/// Extracts a specific attribute value into a variable.
1215///
1216/// This attribute macro retrieves a specific attribute by key and makes it available
1217/// as a typed variable from the request context.
1218///
1219/// # Usage
1220///
1221/// ```rust
1222/// use hyperlane::*;
1223/// use hyperlane_macros::*;
1224/// use serde::Deserialize;
1225///
1226/// const USER_KEY: &str = "user_data";
1227///
1228/// #[derive(Deserialize, Clone)]
1229/// struct User {
1230///     id: u64,
1231///     name: String,
1232/// }
1233///
1234/// #[attribute(USER_KEY => user: User)]
1235/// async fn handle_with_attribute(ctx: Context) {
1236///     if let Some(user_data) = user {
1237///         // Use the extracted attribute
1238///     }
1239/// }
1240/// ```
1241///
1242/// The macro accepts a key-to-variable mapping in the format `key => variable_name: Type`.
1243/// The variable will be available as an `Option<Type>` in the function scope.
1244#[proc_macro_attribute]
1245pub fn attribute(attr: TokenStream, item: TokenStream) -> TokenStream {
1246    attribute_macro(attr, item)
1247}
1248
1249/// Extracts all attributes into a HashMap variable.
1250///
1251/// This attribute macro retrieves all available attributes from the request context
1252/// and makes them available as a HashMap for comprehensive attribute access.
1253///
1254/// # Usage
1255///
1256/// ```rust
1257/// use hyperlane::*;
1258/// use hyperlane_macros::*;
1259///
1260/// #[attributes(all_attrs)]
1261/// async fn handle_with_all_attributes(ctx: Context) {
1262///     for (key, value) in all_attrs {
1263///         // Process each attribute
1264///     }
1265/// }
1266/// ```
1267///
1268/// The macro accepts a variable name that will contain a HashMap of all attributes.
1269/// The variable will be available as a HashMap in the function scope.
1270#[proc_macro_attribute]
1271pub fn attributes(attr: TokenStream, item: TokenStream) -> TokenStream {
1272    attributes_macro(attr, item)
1273}
1274
1275/// Extracts a specific route parameter into a variable.
1276///
1277/// This attribute macro retrieves a specific route parameter by key and makes it
1278/// available as a variable. Route parameters are extracted from the URL path segments.
1279///
1280/// # Usage
1281///
1282/// ```rust
1283/// use hyperlane::*;
1284/// use hyperlane_macros::*;
1285///
1286/// // For route like "/users/{id}"
1287/// #[route_param("id" => user_id)]
1288/// async fn get_user(ctx: Context) {
1289///     if let Some(id) = user_id {
1290///         // Use the route parameter
1291///     }
1292/// }
1293/// ```
1294///
1295/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
1296/// The variable will be available as an `Option<String>` in the function scope.
1297#[proc_macro_attribute]
1298pub fn route_param(attr: TokenStream, item: TokenStream) -> TokenStream {
1299    route_param_macro(attr, item)
1300}
1301
1302/// Extracts all route parameters into a collection variable.
1303///
1304/// This attribute macro retrieves all available route parameters from the URL path
1305/// and makes them available as a collection for comprehensive route parameter access.
1306///
1307/// # Usage
1308///
1309/// ```rust
1310/// use hyperlane::*;
1311/// use hyperlane_macros::*;
1312///
1313/// // For route like "/users/{id}/posts/{post_id}"
1314/// #[route_params(params)]
1315/// async fn handle_nested_route(ctx: Context) {
1316///     for (key, value) in params {
1317///         // Process each route parameter
1318///     }
1319/// }
1320/// ```
1321///
1322/// The macro accepts a variable name that will contain all route parameters.
1323/// The variable will be available as a collection in the function scope.
1324#[proc_macro_attribute]
1325pub fn route_params(attr: TokenStream, item: TokenStream) -> TokenStream {
1326    route_params_macro(attr, item)
1327}
1328
1329/// Extracts a specific request query parameter into a variable.
1330///
1331/// This attribute macro retrieves a specific request query parameter by key and makes it
1332/// available as a variable. Query parameters are extracted from the URL request query string.
1333///
1334/// # Usage
1335///
1336/// ```rust
1337/// use hyperlane::*;
1338/// use hyperlane_macros::*;
1339///
1340/// // For URL like "/search?q=rust&limit=10"
1341/// #[request_query("q" => search_term)]
1342/// async fn search(ctx: Context) {
1343///     if let Some(term) = search_term {
1344///         // Use the request query parameter
1345///     }
1346/// }
1347/// ```
1348///
1349/// The macro accepts a key-to-variable mapping in the format `"key" => variable_name`.
1350/// The variable will be available as an `Option<String>` in the function scope.
1351#[proc_macro_attribute]
1352pub fn request_query(attr: TokenStream, item: TokenStream) -> TokenStream {
1353    request_query_macro(attr, item)
1354}
1355
1356/// Extracts all request query parameters into a collection variable.
1357///
1358/// This attribute macro retrieves all available request query parameters from the URL request query string
1359/// and makes them available as a collection for comprehensive request query parameter access.
1360///
1361/// # Usage
1362///
1363/// ```rust
1364/// use hyperlane::*;
1365/// use hyperlane_macros::*;
1366///
1367/// // For URL like "/search?q=rust&limit=10&sort=date"
1368/// #[request_querys(all_params)]
1369/// async fn search_with_params(ctx: Context) {
1370///     for (key, value) in all_params {
1371///         // Process each request query parameter
1372///     }
1373/// }
1374/// ```
1375///
1376/// The macro accepts a variable name that will contain all request query parameters.
1377/// The variable will be available as a collection in the function scope.
1378#[proc_macro_attribute]
1379pub fn request_querys(attr: TokenStream, item: TokenStream) -> TokenStream {
1380    request_querys_macro(attr, item)
1381}
1382
1383/// Extracts a specific HTTP request header into a variable.
1384///
1385/// This attribute macro retrieves a specific HTTP request header by name and makes it
1386/// available as a variable. Header values are extracted from the request request headers collection.
1387///
1388/// # Usage
1389///
1390/// ```rust
1391/// use hyperlane::*;
1392/// use hyperlane_macros::*;
1393///
1394/// #[request_header(HOST => host_request_header)]
1395/// async fn handle_with_host(ctx: Context) {
1396///     if let Some(host) = host_request_header {
1397///         // Use the host request_header value
1398///     }
1399/// }
1400///
1401/// #[request_header("Content-Type" => content_type)]
1402/// async fn handle_with_content_type(ctx: Context) {
1403///     if let Some(ct) = content_type {
1404///         // Use the content type request_header
1405///     }
1406/// }
1407/// ```
1408///
1409/// The macro accepts a request header name-to-variable mapping in the format `HEADER_NAME => variable_name`
1410/// or `"Header-Name" => variable_name`. The variable will be available as an `Option<String>`.
1411#[proc_macro_attribute]
1412pub fn request_header(attr: TokenStream, item: TokenStream) -> TokenStream {
1413    request_header_macro(attr, item)
1414}
1415
1416/// Extracts all HTTP request headers into a collection variable.
1417///
1418/// This attribute macro retrieves all available HTTP request headers from the request
1419/// and makes them available as a collection for comprehensive request header access.
1420///
1421/// # Usage
1422///
1423/// ```rust
1424/// use hyperlane::*;
1425/// use hyperlane_macros::*;
1426///
1427/// #[request_headers(all_request_headers)]
1428/// async fn handle_with_all_request_headers(ctx: Context) {
1429///     for (name, value) in all_request_headers {
1430///         // Process each request_header
1431///     }
1432/// }
1433/// ```
1434///
1435/// The macro accepts a variable name that will contain all HTTP request headers.
1436/// The variable will be available as a collection in the function scope.
1437#[proc_macro_attribute]
1438pub fn request_headers(attr: TokenStream, item: TokenStream) -> TokenStream {
1439    request_headers_macro(attr, item)
1440}
1441
1442/// Extracts a specific cookie value or all cookies into a variable.
1443///
1444/// This attribute macro supports two syntaxes:
1445/// 1. `cookie(key => variable_name)` - Extract a specific cookie value by key
1446/// 2. `cookie(variable_name)` - Extract all cookies as a raw string
1447///
1448/// # Usage
1449///
1450/// ```rust
1451/// use hyperlane::*;
1452/// use hyperlane_macros::*;
1453///
1454/// #[request_cookie("session_id" => session_cookie_opt)]
1455/// async fn handle_with_session(ctx: Context) {
1456///     if let Some(session) = session_cookie_opt {
1457///         // Use the session cookie value
1458///     }
1459/// }
1460/// ```
1461///
1462/// For specific cookie extraction, the variable will be available as `Option<String>`.
1463/// For all cookies extraction, the variable will be available as `String`.
1464#[proc_macro_attribute]
1465pub fn request_cookie(attr: TokenStream, item: TokenStream) -> TokenStream {
1466    request_cookie_macro(attr, item)
1467}
1468
1469/// Extracts all cookies as a raw string into a variable.
1470///
1471/// This attribute macro retrieves the entire Cookie header from the request and makes it
1472/// available as a String variable. If no Cookie header is present, an empty string is used.
1473///
1474/// # Usage
1475///
1476/// ```rust
1477/// use hyperlane::*;
1478/// use hyperlane_macros::*;
1479///
1480/// #[request_cookies(cookie_value)]
1481/// async fn handle_with_cookies(ctx: Context) {
1482///     // Use the cookie value
1483///     if !cookie_value.is_empty() {
1484///         // Process cookie data
1485///     }
1486/// }
1487/// ```
1488///
1489/// The macro accepts a variable name that will contain the Cookie header value.
1490/// The variable will be available as a String in the function scope.
1491#[proc_macro_attribute]
1492pub fn request_cookies(attr: TokenStream, item: TokenStream) -> TokenStream {
1493    request_cookies_macro(attr, item)
1494}
1495
1496/// Extracts the HTTP request version into a variable.
1497///
1498/// This attribute macro retrieves the HTTP version from the request and makes it
1499/// available as a variable. The version represents the HTTP protocol version used.
1500///
1501/// # Usage
1502///
1503/// ```rust
1504/// use hyperlane::*;
1505/// use hyperlane_macros::*;
1506///
1507/// #[request_version(http_version)]
1508/// async fn handle_with_version(ctx: Context) {
1509///     // Use the HTTP version
1510/// }
1511/// ```
1512///
1513/// The macro accepts a variable name that will contain the HTTP request version.
1514/// The variable will be available as a RequestVersion type in the function scope.
1515#[proc_macro_attribute]
1516pub fn request_version(attr: TokenStream, item: TokenStream) -> TokenStream {
1517    request_version_macro(attr, item)
1518}
1519
1520/// Extracts the HTTP request path into a variable.
1521///
1522/// This attribute macro retrieves the request path from the HTTP request and makes it
1523/// available as a variable. The path represents the URL path portion of the request.
1524///
1525/// # Usage
1526///
1527/// ```rust
1528/// use hyperlane::*;
1529/// use hyperlane_macros::*;
1530///
1531/// #[request_path(request_path)]
1532/// async fn handle_with_path(ctx: Context) {
1533///     // Use the request path
1534///     if request_path.starts_with("/api/") {
1535///         // Handle API requests
1536///     }
1537/// }
1538/// ```
1539///
1540/// The macro accepts a variable name that will contain the HTTP request path.
1541/// The variable will be available as a RequestPath type in the function scope.
1542#[proc_macro_attribute]
1543pub fn request_path(attr: TokenStream, item: TokenStream) -> TokenStream {
1544    request_path_macro(attr, item)
1545}
1546
1547/// Creates a new instance of a specified type with a given variable name.
1548///
1549/// This attribute macro generates an instance initialization at the beginning of the function.
1550///
1551/// # Usage
1552///
1553/// ```rust
1554/// use hyperlane::*;
1555/// use hyperlane_macros::*;
1556///
1557/// #[hyperlane(server: Server)]
1558/// #[tokio::main]
1559/// async fn main() {
1560///     // `server` is now available as: `let server: Server = Server::new().await;`
1561///     // The function body can now use `server`.
1562/// }
1563/// ```
1564///
1565/// The macro accepts a `variable_name: Type` pair.
1566/// The variable will be available as an instance of the specified type in the function scope.
1567#[proc_macro_attribute]
1568pub fn hyperlane(attr: TokenStream, item: TokenStream) -> TokenStream {
1569    hyperlane_macro(attr, item)
1570}
1571
1572/// Registers a function as a route handler.
1573///
1574/// This attribute macro registers the decorated function as a route handler for a given path.
1575/// This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1576///
1577/// # Usage
1578///
1579/// ```rust
1580/// use hyperlane::*;
1581/// use hyperlane_macros::*;
1582///
1583/// #[route("/")]
1584/// async fn route(ctx: Context) {
1585///     // function body
1586/// }
1587/// ```
1588///
1589/// # Parameters
1590///
1591/// - `path`: String literal defining the route path
1592///
1593/// # Dependencies
1594///
1595/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1596#[proc_macro_attribute]
1597pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream {
1598    route_macro(attr, item)
1599}
1600
1601/// Registers a function as a request middleware.
1602///
1603/// This attribute macro registers the decorated function to be executed as a middleware
1604/// for incoming requests. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1605///
1606/// # Note
1607///
1608/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
1609///
1610/// # Usage
1611///
1612/// ```rust
1613/// use hyperlane::*;
1614/// use hyperlane_macros::*;
1615///
1616/// #[request_middleware]
1617/// async fn log_request(ctx: Context) {
1618///     // Middleware logic
1619/// }
1620/// ```
1621///
1622/// # Dependencies
1623///
1624/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1625#[proc_macro_attribute]
1626pub fn request_middleware(attr: TokenStream, item: TokenStream) -> TokenStream {
1627    request_middleware_macro(attr, item)
1628}
1629
1630/// Registers a function as a response middleware.
1631///
1632/// This attribute macro registers the decorated function to be executed as a middleware
1633/// for outgoing responses. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1634///
1635/// # Note
1636///
1637/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
1638///
1639/// # Usage
1640///
1641/// ```rust
1642/// use hyperlane::*;
1643/// use hyperlane_macros::*;
1644///
1645/// #[response_middleware]
1646/// async fn add_custom_header(ctx: Context) {
1647///     // Middleware logic
1648/// }
1649/// ```
1650///
1651/// # Dependencies
1652///
1653/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1654#[proc_macro_attribute]
1655pub fn response_middleware(attr: TokenStream, item: TokenStream) -> TokenStream {
1656    response_middleware_macro(attr, item)
1657}
1658
1659/// Registers a function as a pre-upgrade hook.
1660///
1661/// This attribute macro registers the decorated function to be executed before a connection
1662/// is upgraded (e.g., to WebSocket). This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1663///
1664/// # Note
1665///
1666/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
1667///
1668/// # Usage
1669///
1670/// ```rust
1671/// use hyperlane::*;
1672/// use hyperlane_macros::*;
1673///
1674/// #[pre_upgrade_hook]
1675/// async fn handle_pre_upgrade(ctx: Context) {
1676///     // Pre-upgrade logic
1677/// }
1678/// ```
1679///
1680/// # Dependencies
1681///
1682/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1683#[proc_macro_attribute]
1684pub fn pre_upgrade_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1685    pre_upgrade_hook_macro(attr, item)
1686}
1687
1688/// Registers a function as a connected hook.
1689///
1690/// This attribute macro registers the decorated function to be executed when a new client
1691/// connection is established. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1692///
1693/// # Note
1694///
1695/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
1696///
1697/// # Usage
1698///
1699/// ```rust
1700/// use hyperlane::*;
1701/// use hyperlane_macros::*;
1702///
1703/// #[connected_hook]
1704/// async fn handle_new_connection(ctx: Context) {
1705///     // Connection handling logic
1706/// }
1707/// ```
1708///
1709/// # Dependencies
1710///
1711/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1712#[proc_macro_attribute]
1713pub fn connected_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1714    connected_hook_macro(attr, item)
1715}
1716
1717/// Registers a function as a panic hook.
1718///
1719/// This attribute macro registers the decorated function to handle panics that occur
1720/// during request processing. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1721///
1722/// # Note
1723///
1724/// If an order parameter is not specified, the hook will have a higher priority than hooks with a specified order.
1725///
1726/// # Usage
1727///
1728/// ```rust
1729/// use hyperlane::*;
1730/// use hyperlane_macros::*;
1731///
1732/// #[panic_hook]
1733/// async fn handle_panic(ctx: Context) {
1734///     // Panic handling logic
1735/// }
1736/// ```
1737///
1738/// # Dependencies
1739///
1740/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1741#[proc_macro_attribute]
1742pub fn panic_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1743    panic_hook_macro(attr, item)
1744}
1745
1746/// Disables the default HTTP hook.
1747///
1748/// This attribute macro disables the default HTTP handling logic, allowing for a fully
1749/// custom implementation. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1750///
1751/// # Usage
1752///
1753/// ```rust
1754/// use hyperlane::*;
1755/// use hyperlane_macros::*;
1756///
1757/// #[disable_http_hook("/")]
1758/// async fn custom_http_logic(ctx: Context) {
1759///     // Custom logic to replace default HTTP hook
1760/// }
1761/// ```
1762///
1763/// # Dependencies
1764///
1765/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1766#[proc_macro_attribute]
1767pub fn disable_http_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1768    disable_http_hook_macro(attr, item)
1769}
1770
1771/// Disables the default WebSocket hook.
1772///
1773/// This attribute macro disables the default WebSocket handling logic, allowing for a fully
1774/// custom implementation. This macro requires the `#[hyperlane(server: Server)]` macro to be used to define the server instance.
1775///
1776/// # Usage
1777///
1778/// ```rust
1779/// use hyperlane::*;
1780/// use hyperlane_macros::*;
1781///
1782/// #[disable_ws_hook("/")]
1783/// async fn custom_ws_logic(ctx: Context) {
1784///     // Custom logic to replace default WebSocket hook
1785/// }
1786/// ```
1787///
1788/// # Dependencies
1789///
1790/// This macro depends on the `#[hyperlane(server: Server)]` macro to define the server instance.
1791#[proc_macro_attribute]
1792pub fn disable_ws_hook(attr: TokenStream, item: TokenStream) -> TokenStream {
1793    disable_ws_hook_macro(attr, item)
1794}