HTTP CONNECT: open a tunnel through a proxy
HTTP CONNECT asks a proxy to create a tunnel to a host:port destination. In HTTP/1.1, after a 2xx response, the connection switches to bidirectional byte forwarding immediately after the response headers. A client can then start TLS to the destination inside the tunnel. CONNECT alone does not encrypt the request or verify the destination.
HTTP CONNECT asks a proxy to create a tunnel to a host:port destination. In HTTP/1.1, after a 2xx response, the connection switches to bidirectional byte forwarding immediately after the response headers. A client can then start TLS to the destination inside the tunnel. CONNECT alone does not encrypt the request or verify the destination.
HTTP/1.1 request and response
CONNECT uses host:port as its request target, with an explicit port:
CONNECT api.example.com:443 HTTP/1.1
Host: api.example.com:443
Proxy-Authorization: Basic <credentials>After a successful 2xx response, following bytes are tunnel data, not an HTTP message body. A non-2xx response means no tunnel was established. A successful 2xx response to CONNECT must not include Content-Length or Transfer-Encoding. (RFC 9110 §9.3.6)
How HTTP/2 differs
HTTP/2 creates the tunnel on one stream rather than converting the whole connection. A normal CONNECT request sets :method to CONNECT and :authority to host:port, omitting :scheme and :path. After a 2xx response, DATA frames on that stream carry tunnel bytes; other streams can continue on the same connection. Do not copy HTTP/1.1 request-line or chunked-transfer syntax into HTTP/2. Extended CONNECT, such as a WebSocket bootstrap, is a separately negotiated extension. (RFC 9113 §8.5)
Restrict destinations on a proxy
CONNECT can otherwise let a caller reach arbitrary TCP services. Restrict allowed destination ports and host/IP ranges, require authentication and authorization, and validate resolved addresses against network policy to prevent a destination from resolving to an internal address. RFC 9110 recommends limiting CONNECT to known ports or configurable safe targets. Also set connection, idle, and concurrency limits and define clean shutdown when either side closes.
Use CONNECT when a client must carry TLS or another higher-level protocol through a configured forward proxy. Ordinary API requests and application routing behind a reverse proxy do not need CONNECT. Check proxy authentication and destination rules in the relevant product documentation.
References
[RFC 9110: HTTP Semantics §9.3.6](https://www.rfc-editor.org/rfc/rfc9110.html)
[RFC 9113: HTTP/2 §8.5](https://www.rfc-editor.org/rfc/rfc9113.html)