Skip to content
Docs / Reverse Proxy

Reverse Proxy

Multi-port HTTP/1.x reverse proxy with in-place header rewriting and streaming payloads in services/reverseProxy/reverseProxy.c.

Overview & Status

Status: Available. The Reverse Proxy listens on one or more configured IP:port endpoints (up to VSI_MAX_RP_MAPPINGS = 16) and forwards incoming HTTP/1.x requests to configured backend servers.

When multiple mappings are configured, run_reverse_proxy_service() in src/main.c creates one listener pthread per mapping, each passing its own vsi_rp_mapping_t context into vsi_transport_start().

In-Place Request & Response Rewriting

  • Uses reverse_proxy_transform_request_v2() to modify the parsed HttpRequest in-place—avoiding a second HttpRequest allocation.
  • Saves the incoming Host header into orig_host, replaces Host with the configured backend host[:port] (omitting :80 when target port is 80), removes Proxy-Connection/Expect, and forces Connection: close.
  • Streams request bodies (Content-Length or chunked) to the backend and records nanosecond timestamps before and after upstream first-byte arrival for metrics.
  • Reads upstream response headers up to 16 KB (RP_RESP_HDR_BUF_SIZE) until \r\n\r\n, rewrites occurrences of the backend host[:port] inside Host: and Location: headers back to orig_host, and streams the body in 64 KB chunks until upstream EOF.
  • If DNS resolution or upstream TCP connect fails, sends HTTP/1.1 502 Bad Gateway with Connection: close to the client.

Example & Current Limitations

Verify Reverse Proxy against a local backend on port 3000
# Assuming mapping listen_port=8081 -> target=http://127.0.0.1:3000
curl -i http://127.0.0.1:8081/health
Planned Improvements Not Yet Implemented

Upstream HTTP keep-alive, backend connection pooling, load balancing across multiple targets per port, and TLS termination are not yet implemented. Every request currently uses Connection: close upstream.