Expand description
WiseGate Core - Reusable reverse proxy components
This crate provides the core functionality for building reverse proxies with:
- Rate limiting with sliding window algorithm
- IP filtering and blocking
- HTTP method and URL pattern filtering
- Trusted proxy validation (RFC 7239 compliant)
§Overview
wisegate-core is designed to be framework-agnostic and can be integrated
into any Rust application. Configuration is provided via the ConfigProvider
trait, allowing flexible configuration from any source.
§Example
use wisegate_core::{
RateLimitingProvider, ProxyProvider, FilteringProvider, ConnectionProvider,
AuthenticationProvider, Credentials,
RateLimiter, RateLimitConfig, RateLimitCleanupConfig, ProxyConfig,
};
use std::time::Duration;
// Implement your own configuration provider using composable traits
struct MyConfig {
credentials: Credentials,
}
impl RateLimitingProvider for MyConfig {
fn rate_limit_config(&self) -> &RateLimitConfig {
static CONFIG: RateLimitConfig = RateLimitConfig {
max_requests: 100,
window_duration: Duration::from_secs(60),
};
&CONFIG
}
fn rate_limit_cleanup_config(&self) -> &RateLimitCleanupConfig {
static CONFIG: RateLimitCleanupConfig = RateLimitCleanupConfig {
threshold: 10_000,
interval: Duration::from_secs(60),
};
&CONFIG
}
}
impl ProxyProvider for MyConfig {
fn proxy_config(&self) -> &ProxyConfig {
static CONFIG: ProxyConfig = ProxyConfig {
timeout: Duration::from_secs(30),
max_body_size: 100 * 1024 * 1024,
};
&CONFIG
}
fn allowed_proxy_ips(&self) -> Option<&[String]> { None }
}
impl FilteringProvider for MyConfig {
fn blocked_ips(&self) -> &[String] { &[] }
fn blocked_methods(&self) -> &[String] { &[] }
fn blocked_patterns(&self) -> &[String] { &[] }
}
impl ConnectionProvider for MyConfig {
fn max_connections(&self) -> usize { 10_000 }
}
impl AuthenticationProvider for MyConfig {
fn auth_credentials(&self) -> &Credentials { &self.credentials }
fn auth_realm(&self) -> &str { "WiseGate" }
fn bearer_token(&self) -> Option<&str> { None }
}
// Create a rate limiter
let limiter = RateLimiter::new();§Modules
types- Core types and theConfigProvidertraiterror- Error types and result aliasesheaders- HTTP header constantsip_filter- IP validation, extraction, and filteringrate_limiter- Rate limiting implementationrequest_handler- HTTP request processing and forwarding
Re-exports§
pub use auth::Credential;pub use auth::Credentials;pub use auth::check_basic_auth;pub use auth::check_bearer_token;pub use error::Result;pub use error::WiseGateError;pub use types::AuthenticationProvider;pub use types::ConfigProvider;pub use types::ConnectionProvider;pub use types::FilteringProvider;pub use types::ProxyConfig;pub use types::ProxyProvider;pub use types::RateLimitCleanupConfig;pub use types::RateLimitConfig;pub use types::RateLimitEntry;pub use types::RateLimiter;pub use types::RateLimitingProvider;
Modules§
- auth
- Authentication module for HTTP Basic Authentication (RFC 7617) and Bearer Token (RFC 6750).
- defaults
- Default configuration values for WiseGate.
- error
- Error types for WiseGate.
- headers
- HTTP header constants for WiseGate.
- ip_
filter - IP filtering and validation for WiseGate.
- rate_
limiter - Rate limiting implementation for WiseGate.
- request_
handler - HTTP request handling and proxying.
- types
- Type definitions for WiseGate configuration and state management.