Skip to main content

grapsus_proxy/
lib.rs

1// Allow lints for work-in-progress features and code patterns
2#![allow(dead_code)]
3#![allow(unused_variables)]
4#![allow(unused_imports)]
5#![allow(clippy::too_many_arguments)]
6#![allow(clippy::match_like_matches_macro)]
7#![allow(clippy::manual_strip)]
8#![allow(clippy::only_used_in_recursion)]
9#![allow(clippy::type_complexity)]
10#![allow(clippy::manual_try_fold)]
11#![allow(private_interfaces)]
12
13//! Grapsus Proxy Library
14//!
15//! A security-first reverse proxy built on Pingora with sleepable ops at the edge.
16//!
17//! This library provides the core components for building a production-grade
18//! reverse proxy with:
19//!
20//! - **Routing**: Flexible path-based and header-based routing
21//! - **Upstream Management**: Load balancing, health checking, circuit breakers
22//! - **Static File Serving**: Compression, caching, range requests
23//! - **Validation**: JSON Schema validation for API requests/responses
24//! - **Error Handling**: Customizable error pages per service type
25//! - **Hot Reload**: Configuration changes without restarts
26//!
27//! # Example
28//!
29//! ```ignore
30//! use grapsus_proxy::{StaticFileServer, ErrorHandler, SchemaValidator};
31//! use grapsus_config::{StaticFileConfig, ServiceType};
32//!
33//! // Create a static file server
34//! let config = StaticFileConfig::default();
35//! let server = StaticFileServer::new(config);
36//!
37//! // Create an error handler for API responses
38//! let handler = ErrorHandler::new(ServiceType::Api, None);
39//! ```
40
41// ============================================================================
42// Module Declarations
43// ============================================================================
44
45pub mod acme;
46pub mod agents;
47pub mod app;
48pub mod builtin_handlers;
49pub mod cache;
50pub mod decompression;
51pub mod discovery;
52pub mod disk_cache;
53pub mod distributed_rate_limit;
54pub mod errors;
55pub mod hybrid_cache;
56pub mod memcached_rate_limit;
57
58// Kubernetes kubeconfig parsing (requires kubernetes feature)
59pub mod geo_filter;
60pub mod grpc_health;
61pub mod health;
62pub mod http_helpers;
63pub mod inference;
64#[cfg(feature = "kubernetes")]
65pub mod kubeconfig;
66pub mod logging;
67pub mod memory_cache;
68pub mod metrics;
69pub mod otel;
70pub mod proxy;
71pub mod rate_limit;
72pub mod reload;
73pub mod routing;
74pub mod scoped_circuit_breaker;
75pub mod scoped_rate_limit;
76pub mod scoped_routing;
77pub mod shadow;
78pub mod static_files;
79pub mod tls;
80pub mod trace_id;
81pub mod upstream;
82pub mod validation;
83pub mod websocket;
84
85// Bundle management (agent installation)
86pub mod bundle;
87
88// ============================================================================
89// Public API Re-exports
90// ============================================================================
91
92// Error handling
93pub use errors::ErrorHandler;
94
95// Static file serving
96pub use static_files::{CacheStats, CachedFile, FileCache, StaticFileServer};
97
98// Request validation
99pub use validation::SchemaValidator;
100
101// Routing
102pub use routing::{RequestInfo, RouteMatch, RouteMatcher};
103pub use scoped_routing::{ScopedRouteMatch, ScopedRouteMatcher};
104
105// Upstream management
106pub use upstream::{
107    LoadBalancer, PoolConfigSnapshot, PoolStats, RequestContext, ShadowTarget, TargetSelection,
108    UpstreamPool, UpstreamTarget,
109};
110
111// Health checking
112pub use health::{ActiveHealthChecker, PassiveHealthChecker, TargetHealthInfo};
113
114// Agents
115pub use agents::{AgentAction, AgentCallContext, AgentDecision, AgentManager};
116
117// Hot reload
118pub use reload::{ConfigManager, ReloadEvent, ReloadTrigger, SignalManager, SignalType};
119
120// Application state
121pub use app::AppState;
122
123// Proxy core
124pub use proxy::GrapsusProxy;
125
126// Built-in handlers
127pub use builtin_handlers::{
128    execute_handler, BuiltinHandlerState, CachePurgeRequest, TargetHealthStatus, TargetStatus,
129    UpstreamHealthSnapshot, UpstreamStatus,
130};
131
132// HTTP helpers
133pub use http_helpers::{
134    extract_request_info, get_or_create_trace_id, write_error, write_json_error, write_response,
135    write_text_error, OwnedRequestInfo,
136};
137
138// Trace ID generation (TinyFlake)
139pub use trace_id::{
140    generate_for_format, generate_tinyflake, generate_uuid, TraceIdFormat, TINYFLAKE_LENGTH,
141};
142
143// OpenTelemetry tracing
144pub use otel::{
145    create_traceparent, generate_span_id, generate_trace_id, get_tracer, init_tracer,
146    shutdown_tracer, OtelError, OtelTracer, RequestSpan, TraceContext, TRACEPARENT_HEADER,
147    TRACESTATE_HEADER,
148};
149
150// TLS / SNI support
151pub use tls::{
152    build_server_config, build_upstream_tls_config, load_client_ca, validate_tls_config,
153    validate_upstream_tls_config, CertificateReloader, HotReloadableSniResolver, OcspCacheEntry,
154    OcspStapler, SniResolver, TlsError,
155};
156
157// Logging
158pub use logging::{
159    AccessLogEntry, AccessLogFormat, AuditEventType, AuditLogEntry, ErrorLogEntry, LogManager,
160    SharedLogManager,
161};
162
163// Rate limiting
164pub use rate_limit::{
165    RateLimitConfig, RateLimitManager, RateLimitOutcome, RateLimitResult, RateLimiterPool,
166};
167
168// Scoped rate limiting
169pub use scoped_rate_limit::{ScopedRateLimitManager, ScopedRateLimitResult};
170
171// Scoped circuit breakers
172pub use scoped_circuit_breaker::{ScopedBreakerStatus, ScopedCircuitBreakerManager};
173
174// Traffic mirroring / shadowing
175pub use shadow::{buffer_request_body, clone_body_for_shadow, should_buffer_method, ShadowManager};
176
177// GeoIP filtering
178pub use geo_filter::{
179    GeoDatabaseWatcher, GeoFilterManager, GeoFilterPool, GeoFilterResult, GeoLookupError,
180};
181
182// Body decompression with ratio limits
183pub use decompression::{
184    decompress_body, decompress_body_with_stats, is_supported_encoding, parse_content_encoding,
185    DecompressionConfig, DecompressionError, DecompressionResult, DecompressionStats,
186};
187
188// Distributed rate limiting - Redis
189#[cfg(feature = "distributed-rate-limit")]
190pub use distributed_rate_limit::{
191    create_redis_rate_limiter, DistributedRateLimitStats, RedisRateLimiter,
192};
193
194// Distributed rate limiting - Memcached
195#[cfg(feature = "distributed-rate-limit-memcached")]
196pub use memcached_rate_limit::{
197    create_memcached_rate_limiter, MemcachedRateLimitStats, MemcachedRateLimiter,
198};
199
200// HTTP caching
201pub use cache::{
202    configure_cache, get_cache_eviction, get_cache_lock, get_cache_storage, init_disk_cache_state,
203    is_cache_enabled, save_disk_cache_state, CacheConfig, CacheManager, HttpCacheStats,
204};
205
206// Memory caching
207pub use memory_cache::{
208    MemoryCacheConfig, MemoryCacheManager, MemoryCacheStats, RouteMatchEntry, TypedCache,
209};
210
211// Prometheus metrics
212pub use metrics::{MetricsManager, MetricsResponse};
213
214// Service discovery
215pub use discovery::{
216    ConsulDiscovery, DiscoveryConfig, DiscoveryManager, DnsDiscovery, KubernetesDiscovery,
217};
218
219// Kubernetes kubeconfig parsing
220#[cfg(feature = "kubernetes")]
221pub use kubeconfig::{KubeAuth, Kubeconfig, KubeconfigError, ResolvedKubeConfig};
222
223// Re-export common error types for convenience
224pub use grapsus_common::errors::{LimitType, GrapsusError, GrapsusResult};