Skip to main content

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//!     AuthenticationProvider, Credentials,
21//!     RateLimiter, RateLimitConfig, RateLimitCleanupConfig, ProxyConfig,
22//! };
23//! use std::time::Duration;
24//!
25//! // Implement your own configuration provider using composable traits
26//! struct MyConfig {
27//!     credentials: Credentials,
28//! }
29//!
30//! impl RateLimitingProvider for MyConfig {
31//!     fn rate_limit_config(&self) -> &RateLimitConfig {
32//!         static CONFIG: RateLimitConfig = RateLimitConfig {
33//!             max_requests: 100,
34//!             window_duration: Duration::from_secs(60),
35//!         };
36//!         &CONFIG
37//!     }
38//!
39//!     fn rate_limit_cleanup_config(&self) -> &RateLimitCleanupConfig {
40//!         static CONFIG: RateLimitCleanupConfig = RateLimitCleanupConfig {
41//!             threshold: 10_000,
42//!             interval: Duration::from_secs(60),
43//!         };
44//!         &CONFIG
45//!     }
46//! }
47//!
48//! impl ProxyProvider for MyConfig {
49//!     fn proxy_config(&self) -> &ProxyConfig {
50//!         static CONFIG: ProxyConfig = ProxyConfig {
51//!             timeout: Duration::from_secs(30),
52//!             max_body_size: 100 * 1024 * 1024,
53//!         };
54//!         &CONFIG
55//!     }
56//!
57//!     fn allowed_proxy_ips(&self) -> Option<&[String]> { None }
58//! }
59//!
60//! impl FilteringProvider for MyConfig {
61//!     fn blocked_ips(&self) -> &[String] { &[] }
62//!     fn blocked_methods(&self) -> &[String] { &[] }
63//!     fn blocked_patterns(&self) -> &[String] { &[] }
64//! }
65//!
66//! impl ConnectionProvider for MyConfig {
67//!     fn max_connections(&self) -> usize { 10_000 }
68//! }
69//!
70//! impl AuthenticationProvider for MyConfig {
71//!     fn auth_credentials(&self) -> &Credentials { &self.credentials }
72//!     fn auth_realm(&self) -> &str { "WiseGate" }
73//! }
74//!
75//! // Create a rate limiter
76//! let limiter = RateLimiter::new();
77//! ```
78//!
79//! # Modules
80//!
81//! - [`types`] - Core types and the [`ConfigProvider`] trait
82//! - [`error`] - Error types and result aliases
83//! - [`headers`] - HTTP header constants
84//! - [`ip_filter`] - IP validation, extraction, and filtering
85//! - [`rate_limiter`] - Rate limiting implementation
86//! - [`request_handler`] - HTTP request processing and forwarding
87
88#![forbid(unsafe_code)]
89
90pub mod auth;
91pub mod error;
92pub mod headers;
93pub mod ip_filter;
94pub mod rate_limiter;
95pub mod request_handler;
96#[cfg(test)]
97pub mod test_utils;
98pub mod types;
99
100// Re-export commonly used items at crate root
101pub use auth::{Credential, Credentials, check_basic_auth};
102pub use error::{Result, WiseGateError};
103pub use types::{
104    // Composable configuration traits
105    AuthenticationProvider,
106    // Aggregated configuration trait
107    ConfigProvider,
108    ConnectionProvider,
109    FilteringProvider,
110    // Configuration structs
111    ProxyConfig,
112    ProxyProvider,
113    RateLimitCleanupConfig,
114    RateLimitConfig,
115    // Rate limiting types
116    RateLimitEntry,
117    RateLimiter,
118    RateLimitingProvider,
119};