wisegate_core/lib.rs
1//! WiseGate Core - Reusable reverse proxy components
2//!
3//! This crate provides the core functionality for building reverse proxies with:
4//! - Rate limiting with sliding window algorithm
5//! - IP filtering and blocking
6//! - HTTP method and URL pattern filtering
7//! - Trusted proxy validation (RFC 7239 compliant)
8//!
9//! # Overview
10//!
11//! `wisegate-core` is designed to be framework-agnostic and can be integrated
12//! into any Rust application. Configuration is provided via the [`ConfigProvider`]
13//! trait, allowing flexible configuration from any source.
14//!
15//! # Example
16//!
17//! ```rust,no_run
18//! use wisegate_core::{
19//! RateLimitingProvider, ProxyProvider, FilteringProvider, ConnectionProvider,
20//! RateLimiter, RateLimitConfig, RateLimitCleanupConfig, ProxyConfig,
21//! };
22//! use std::time::Duration;
23//!
24//! // Implement your own configuration provider using composable traits
25//! struct MyConfig;
26//!
27//! impl RateLimitingProvider for MyConfig {
28//! fn rate_limit_config(&self) -> &RateLimitConfig {
29//! static CONFIG: RateLimitConfig = RateLimitConfig {
30//! max_requests: 100,
31//! window_duration: Duration::from_secs(60),
32//! };
33//! &CONFIG
34//! }
35//!
36//! fn rate_limit_cleanup_config(&self) -> &RateLimitCleanupConfig {
37//! static CONFIG: RateLimitCleanupConfig = RateLimitCleanupConfig {
38//! threshold: 10_000,
39//! interval: Duration::from_secs(60),
40//! };
41//! &CONFIG
42//! }
43//! }
44//!
45//! impl ProxyProvider for MyConfig {
46//! fn proxy_config(&self) -> &ProxyConfig {
47//! static CONFIG: ProxyConfig = ProxyConfig {
48//! timeout: Duration::from_secs(30),
49//! max_body_size: 100 * 1024 * 1024,
50//! };
51//! &CONFIG
52//! }
53//!
54//! fn allowed_proxy_ips(&self) -> Option<&[String]> { None }
55//! }
56//!
57//! impl FilteringProvider for MyConfig {
58//! fn blocked_ips(&self) -> &[String] { &[] }
59//! fn blocked_methods(&self) -> &[String] { &[] }
60//! fn blocked_patterns(&self) -> &[String] { &[] }
61//! }
62//!
63//! impl ConnectionProvider for MyConfig {
64//! fn max_connections(&self) -> usize { 10_000 }
65//! }
66//!
67//! // Create a rate limiter
68//! let limiter = RateLimiter::new();
69//! ```
70//!
71//! # Modules
72//!
73//! - [`types`] - Core types and the [`ConfigProvider`] trait
74//! - [`error`] - Error types and result aliases
75//! - [`headers`] - HTTP header constants
76//! - [`ip_filter`] - IP validation, extraction, and filtering
77//! - [`rate_limiter`] - Rate limiting implementation
78//! - [`request_handler`] - HTTP request processing and forwarding
79
80#![forbid(unsafe_code)]
81
82pub mod error;
83pub mod headers;
84pub mod ip_filter;
85pub mod rate_limiter;
86pub mod request_handler;
87#[cfg(test)]
88pub mod test_utils;
89pub mod types;
90
91// Re-export commonly used items at crate root
92pub use error::{Result, WiseGateError};
93pub use types::{
94 // Aggregated configuration trait
95 ConfigProvider,
96 // Composable configuration traits
97 ConnectionProvider,
98 FilteringProvider,
99 // Configuration structs
100 ProxyConfig,
101 ProxyProvider,
102 RateLimitCleanupConfig,
103 RateLimitConfig,
104 // Rate limiting types
105 RateLimitEntry,
106 RateLimiter,
107 RateLimitingProvider,
108};