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//! fn bearer_token(&self) -> Option<&str> { None }
74//! }
75//!
76//! // Create a rate limiter
77//! let limiter = RateLimiter::new();
78//! ```
79//!
80//! # Modules
81//!
82//! - [`types`] - Core types and the [`ConfigProvider`] trait
83//! - [`error`] - Error types and result aliases
84//! - [`headers`] - HTTP header constants
85//! - [`ip_filter`] - IP validation, extraction, and filtering
86//! - [`rate_limiter`] - Rate limiting implementation
87//! - [`request_handler`] - HTTP request processing and forwarding
88
89#![forbid(unsafe_code)]
90
91pub mod auth;
92pub mod defaults;
93pub mod error;
94pub mod headers;
95pub mod ip_filter;
96pub mod rate_limiter;
97pub mod request_handler;
98#[cfg(test)]
99pub mod test_utils;
100pub mod types;
101
102// Re-export commonly used items at crate root
103pub use auth::{Credential, Credentials, check_basic_auth, check_bearer_token};
104pub use error::{Result, WiseGateError};
105pub use types::{
106 // Composable configuration traits
107 AuthenticationProvider,
108 // Aggregated configuration trait
109 ConfigProvider,
110 ConnectionProvider,
111 FilteringProvider,
112 // Configuration structs
113 ProxyConfig,
114 ProxyProvider,
115 RateLimitCleanupConfig,
116 RateLimitConfig,
117 // Rate limiting types
118 RateLimitEntry,
119 RateLimiter,
120 RateLimitingProvider,
121};