1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Middleware system for Ferro framework
//!
//! This module provides Laravel 12.x-style middleware support with:
//! - Global middleware (runs on all routes)
//! - Route group middleware (shared for a group of routes)
//! - Per-route middleware (applied to individual routes)
//! - Rate limiting middleware for API protection
//!
//! # Example
//!
//! ```rust,ignore
//! use ferro_rs::{async_trait, Middleware, Next, Request, Response, HttpResponse};
//!
//! pub struct AuthMiddleware;
//!
//! #[async_trait]
//! impl Middleware for AuthMiddleware {
//! async fn handle(&self, request: Request, next: Next) -> Response {
//! if request.header("Authorization").is_none() {
//! return Err(HttpResponse::text("Unauthorized").status(401));
//! }
//! next(request).await
//! }
//! }
//! ```
//!
//! # Rate Limiting
//!
//! ```rust,ignore
//! use ferro::middleware::{RateLimiter, Limit, Throttle};
//!
//! // Register named limiter
//! RateLimiter::define("api", |req| Limit::per_minute(60));
//!
//! // Apply to routes
//! get!("/api/users", handler).middleware(Throttle::named("api"))
//!
//! // Inline limit
//! get!("/health", handler).middleware(Throttle::per_minute(120))
//! ```
pub use MetricsMiddleware;
pub use SecurityHeaders;
pub use MiddlewareChain;
pub use ;
pub use get_global_middleware_info;
pub use register_global_middleware;
pub use MiddlewareRegistry;
use crate;
use async_trait;
use Future;
use Pin;
use Arc;
/// Type alias for the boxed future returned by middleware
pub type MiddlewareFuture = ;
/// Type alias for the next handler in the middleware chain
///
/// Call `next(request).await` to pass control to the next middleware or the route handler.
pub type Next = ;
/// Type alias for boxed middleware handlers (internal use)
pub type BoxedMiddleware = ;
/// Trait for implementing middleware
///
/// Middleware can inspect/modify requests, short-circuit responses, or pass control
/// to the next middleware in the chain by calling `next(request).await`.
///
/// # Example
///
/// ```rust,ignore
/// use ferro_rs::{async_trait, Middleware, Next, Request, Response, HttpResponse};
///
/// pub struct LoggingMiddleware;
///
/// #[async_trait]
/// impl Middleware for LoggingMiddleware {
/// async fn handle(&self, request: Request, next: Next) -> Response {
/// println!("--> {} {}", request.method(), request.path());
/// let response = next(request).await;
/// println!("<-- complete");
/// response
/// }
/// }
/// ```
/// Convert a Middleware trait object into a BoxedMiddleware