Skip to content
Docs / Forward Proxy

Forward Proxy

HTTP/1.x request forwarding, body streaming, and HTTPS CONNECT tunneling implemented in services/forwardProxy/forwardProxy.c.

Overview & Status

Status: Available. The Forward Proxy acts as an intermediary between client applications and destination servers over HTTP/1.x and TCP tunnels established via the HTTP CONNECT method.

HTTP/1.x Request Forwarding

  • Reads incoming request headers up to 16 KB (HTTP1_HEADER_BUFFER_SIZE) and determines body framing via http1_read_and_parse_headers().
  • Parses absolute-form URIs (e.g. http://example.com:8080/path) or falls back to the Host header when a relative path is received. Defaults to port 80 if omitted.
  • Converts the outbound request URI to origin-form (e.g. /path), strips hop-by-hop headers Proxy-Connection and Expect, and appends Connection: close.
  • Resolves the destination host via getaddrinfo() (AF_INET, SOCK_STREAM) and opens a TCP connection via outbound_connect_tcp().
  • If Expect: 100-continue is present alongside a body, immediately sends HTTP/1.1 100 Continue to the client before streaming.
  • Streams request bodies of arbitrary size using Content-Length or Transfer-Encoding: chunked framing via http1_stream_request_body(), then relays upstream response bytes until EOF.

HTTPS CONNECT Tunneling

When the client sends a CONNECT method (for example CONNECT example.com:443 HTTP/1.1), forward_proxy_transform_request() parses the authority host and port (defaulting to 443). After establishing the upstream TCP socket, VSI replies:

CONNECT tunnel handshake response
HTTP/1.1 200 Connection Established

Traffic is then forwarded bidirectionally between client_fd and outstream_fd inside handle_request_through_tunnel_tracked() using select() multiplexing and a 64 KB stack buffer (TUNNEL_BUFFER_SIZE = 65536) until either side closes or errors.

Usage Example & Known Limitations

Test Forward Proxy with curl
# HTTP request through forward proxy
curl -x http://127.0.0.1:8085 http://example.com/
# HTTPS request via CONNECT tunnel
curl -x http://127.0.0.1:8085 https://example.com/
Current Limitations

The Forward Proxy does not implement Proxy-Authorization, response caching, domain allow/deny rules, IPv6 upstream DNS (AF_INET only), or SOCKS protocols.