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