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