pub async fn handle_request<C: ConfigProvider>(
req: Request<Incoming>,
forward_host: Arc<str>,
forward_port: u16,
limiter: RateLimiter,
config: Arc<C>,
http_client: Client,
) -> Result<Response<Full<Bytes>>, Infallible>Expand description
Handles an incoming HTTP request through the proxy pipeline.
This is the main entry point for request processing. It performs:
- Client IP extraction and validation from proxy headers
- IP blocking checks
- URL pattern blocking (e.g.,
.php,.envfiles) - HTTP method blocking (e.g.,
PUT,DELETE) - Rate limiting per client IP
- Request forwarding to the upstream service
§Arguments
req- The incoming HTTP requestforward_host- The upstream host to forward requests toforward_port- The upstream port to forward requests tolimiter- The shared rate limiter instanceconfig- Configuration provider for all settingshttp_client- HTTP client for forwarding requests (with connection pooling)
§Returns
Always returns Ok with either:
- A successful proxied response from upstream
- An error response (403, 404, 405, 429, 502, etc.)
§Runtime
This is an async function backed by reqwest/tokio; it must be awaited
from inside a Tokio runtime (#[tokio::main], Runtime::block_on, etc.).
§Security
- Strict mode (proxy allowlist configured): both
X-Forwarded-ForandForwardedheaders must be present. The proxy IP is taken from theForwardedheader’sby=field and matched against the allowlist; the client IP is taken from the last entry ofX-Forwarded-For. Requests missing either header, or whose proxy is not in the allowlist, are rejected with400 Bad Request. - Permissive mode (no allowlist): if a request supplies an
X-Forwarded-FororForwardedheader, the parsed IP is trusted as the real client IP and re-emitted to the upstream asX-Real-IP. An attacker can spoof this value by sending fake headers — only enable permissive mode when the proxy sits behind another layer that strips or normalises these headers. - Any client-supplied
X-Real-IPheader is stripped before processing. - The
Authorizationheader is stripped before forwarding whenever wisegate performed authentication (seecrate::AuthenticationProvider::forward_authorization_header).