The HTTP CONNECT Method Explained
The HTTP CONNECT method is a critical piece of internet infrastructure that most users never think about. Every time your browser accesses an HTTPS website through a proxy, it uses CONNECT to establish a secure tunnel. But CONNECT's capabilities extend far beyond HTTPS — it can tunnel any TCP protocol through HTTP proxy infrastructure.
Origins and Purpose
The CONNECT method was introduced to solve a specific problem: how to access HTTPS websites through an HTTP proxy. Since HTTP proxies operate at the application layer and need to read HTTP requests, they cannot process encrypted HTTPS traffic in the normal way. CONNECT provides an escape hatch — it tells the proxy to stop being an HTTP intermediary and start being a TCP relay.
How CONNECT Works Step by Step
**Step 1 — CONNECT Request**
The client sends a standard HTTP request, but instead of a resource path, it specifies a hostname and port:
CONNECT api.example.com:443 HTTP/1.1
Host: api.example.com:443
Proxy-Authorization: Basic dXNlcjpwYXNzThis is the only point where HTTP semantics are used. The proxy reads this request, authenticates the client, and decides whether to allow the tunnel.
**Step 2 — Proxy Establishes Connection**
The proxy opens a TCP connection to the target host on the specified port. If the connection succeeds, the proxy responds:
HTTP/1.1 200 Connection EstablishedIf it fails, the proxy returns an appropriate error: - `403 Forbidden` — policy does not allow this tunnel - `502 Bad Gateway` — could not connect to the target - `504 Gateway Timeout` — target did not respond
**Step 3 — Transparent Relay**
After the 200 response, the proxy becomes invisible. It forwards every byte from the client to the server and vice versa, without parsing, modifying, or inspecting the data. The client and server communicate as if directly connected.
Beyond HTTPS: Advanced Tunneling
While HTTPS is the primary use case for CONNECT, the method is protocol-agnostic. Any TCP protocol can be tunneled:
**WebSocket over HTTP Proxy**: WebSocket upgrade requests can be tunneled through CONNECT. The client establishes a CONNECT tunnel to the WebSocket server, then performs the WebSocket handshake inside the tunnel.
**SSH over HTTP Proxy**: In restrictive network environments that only allow HTTP proxy traffic, SSH connections can be tunneled using CONNECT to port 22. Tools like `corkscrew` and ProxyCommand automate this.
**Database Connections**: MySQL, PostgreSQL, and other database connections can traverse HTTP proxies using CONNECT tunnels, enabling database access from networks restricted to HTTP proxy egress.
Security Model
CONNECT's security model has important nuances:
- **Pre-tunnel phase**: The CONNECT request itself, including proxy authentication credentials, travels unencrypted between client and proxy. This is the window where credentials could be intercepted on the client-to-proxy link.
2. **Tunnel phase**: Once established, the proxy cannot read tunnel contents. If TLS is negotiated inside the tunnel, the encryption is end-to-end between client and target server. The proxy is cryptographically excluded.
3. **Metadata visibility**: The proxy always sees the target hostname and port from the CONNECT request. It also sees traffic volume and timing patterns, but not content.
Port Restrictions
Many proxies restrict which ports CONNECT can target. The most common policy allows only port 443 (HTTPS). This prevents tunneling to arbitrary services but limits the flexibility of CONNECT. Hex Proxies supports CONNECT to any port, giving you full flexibility to tunnel any TCP protocol through our infrastructure.
Connection Lifecycle
A CONNECT tunnel persists until either the client or server closes the TCP connection, or the proxy detects an idle timeout. For long-lived connections (WebSocket, SSH sessions), ensure your proxy supports appropriate timeout configurations. Hex Proxies supports configurable keep-alive intervals for CONNECT tunnels.
Using CONNECT with Hex Proxies
When you configure an HTTP proxy with Hex Proxies and access an HTTPS URL, the CONNECT tunnel is established automatically by your HTTP client library. No special configuration is needed — the client detects the HTTPS scheme and switches to CONNECT mode.
For tunneling non-HTTPS protocols, you may need to explicitly establish a CONNECT tunnel using your client library's lower-level API or a dedicated tunneling tool. Hex Proxies supports CONNECT tunnels to any destination port with the same authentication and IP rotation features available for standard HTTP proxying.
Practical Considerations
CONNECT tunnels are stateless from the proxy's perspective — each tunnel is an independent TCP connection. If you need to route thousands of concurrent tunnels, Hex Proxies' infrastructure handles connection pooling and resource management automatically. There is no per-tunnel surcharge or special billing for CONNECT tunnels.