Production-style reverse proxy focused on correctness, resiliency, and observability.
- Clear service architecture with separated stages: ingress, routing, request/response transforms, upstream client, and telemetry.
- Real operational features: health checks, readiness checks, graceful shutdown/drain, backpressure controls.
- Resilience controls implemented in code: retries with backoff and jitter, health-aware routing, per-upstream circuit breaker.
- Security hardening: trusted proxy policy for forwarded headers and optional bearer auth for
/metrics. - Automated quality gates in CI: format check, clippy (warnings denied), and full test suite.
- Integration tests validating behavior under failure and load-like conditions.
Request flow:
Ingress -> Routing/LB -> Request modifiers -> Upstream client -> Response modifiers -> Metrics/Tracing
Core code paths:
src/ingress/handler.rssrc/routing/load_balancer.rssrc/request/modifier.rssrc/client/upstream.rssrc/response/modifier.rssrc/metrics/tracer.rs
- Reverse proxying with round-robin load balancing across multiple upstreams.
- Health-aware routing and active health probing.
- Circuit breaker (closed/open/half-open) per upstream.
- Retry policy for idempotent requests with exponential backoff and jitter.
- Connect timeout and request timeout controls.
- Backpressure via
max_in_flightsemaphore. - Streaming mode for large request bodies.
- Graceful shutdown with drain mode and timeout.
- Endpoints:
/healthz,/healthz?check=upstream,/readyz,/metrics. - Request/response correctness: hop-by-hop header stripping, host rewrite, forwarded headers.
- Path normalization for metrics labels to avoid high-cardinality explosions.
- Trusted proxy CIDRs via
REVERSE_PROXY_TRUSTED_PROXIES. - Untrusted clients cannot spoof
X-Forwarded-For/X-Forwarded-Proto. - Optional
/metricsbearer token viaREVERSE_PROXY_METRICS_BEARER_TOKEN. - Debug upstream header exposure is opt-in (
REVERSE_PROXY_EXPOSE_DEBUG_HEADERS).
- Backpressure proof screenshot:
docs/proof/pressure.png - Health behavior screenshot:
docs/proof/health.png - Test run proof:
docs/proof/proxy_features_output.txt - Metrics sample:
docs/proof/metrics_sample.txt
Example metrics excerpt:
# TYPE requests_total counter
requests_total{method="GET",path="/users/:id",status="502",status_class="5xx"} 2
requests_total{method="GET",path="/metrics",status="200",status_class="2xx"} 1
# TYPE request_latency_seconds summary
request_latency_seconds_sum{method="GET",path="/users/:id",status="502",status_class="5xx"} 0.012
- Start two upstreams:
py -m http.server 9000
py -m http.server 9001- In another terminal, run the proxy:
$env:REVERSE_PROXY_UPSTREAMS="http://127.0.0.1:9000,http://127.0.0.1:9001"
$env:REVERSE_PROXY_HEALTHCHECK="true"
$env:REVERSE_PROXY_TRUSTED_PROXIES="127.0.0.1/32"
cargo run- Verify endpoints:
curl http://127.0.0.1:8000/healthz
curl http://127.0.0.1:8000/readyz
curl http://127.0.0.1:8000/metricsIf you enable metrics auth:
$env:REVERSE_PROXY_METRICS_BEARER_TOKEN="secret-token"
curl -H "Authorization: Bearer secret-token" http://127.0.0.1:8000/metricspython3 -m http.server 9000
python3 -m http.server 9001export REVERSE_PROXY_UPSTREAMS="http://127.0.0.1:9000,http://127.0.0.1:9001"
export REVERSE_PROXY_HEALTHCHECK=true
export REVERSE_PROXY_TRUSTED_PROXIES="127.0.0.1/32"
cargo runcurl http://127.0.0.1:8000/healthz
curl http://127.0.0.1:8000/readyz
curl http://127.0.0.1:8000/metricscargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo testREVERSE_PROXY_UPSTREAMS: comma-separated upstream URLs.REVERSE_PROXY_CONNECT_TIMEOUT_MS: upstream connect timeout.REVERSE_PROXY_MAX_IN_FLIGHT: max concurrent in-flight requests.REVERSE_PROXY_STREAM_LARGE_BODIES: enable streaming for large bodies.REVERSE_PROXY_STREAM_THRESHOLD_BYTES: streaming threshold.REVERSE_PROXY_HEALTHCHECK: enable active health checks.REVERSE_PROXY_HEALTHCHECK_INTERVAL_SECS: health check interval.REVERSE_PROXY_SHUTDOWN_GRACE_SECONDS: graceful drain timeout.REVERSE_PROXY_CIRCUIT_BREAKER: enable per-upstream breaker.REVERSE_PROXY_CIRCUIT_BREAKER_FAILURE_THRESHOLD: failures before open.REVERSE_PROXY_CIRCUIT_BREAKER_OPEN_MS: open-state duration.REVERSE_PROXY_RETRY_BACKOFF_BASE_MS: retry backoff base.REVERSE_PROXY_RETRY_BACKOFF_MAX_MS: retry backoff cap.REVERSE_PROXY_TRUSTED_PROXIES: trusted proxy IP/CIDR list.REVERSE_PROXY_METRICS_BEARER_TOKEN: optional bearer token for/metrics.REVERSE_PROXY_EXPOSE_DEBUG_HEADERS: expose internal debug headers.
Workflow: .github/workflows/ci.yml
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all --all-features- Runs on Ubuntu and Windows