What is the HTTP CONNECT method?
Definition
The HTTP method that asks a proxy to open a raw TCP tunnel to a host and port. It is how HTTPS, and anything else, passes through an HTTP proxy.
A proxy cannot read an encrypted request to find out where it is going, so the client tells it in plain text first. CONNECT names a host and a port and nothing else. If the proxy answers with any 2xx status, RFC 9110 says it switches to blind forwarding in both directions until either side closes, and everything after that is between your client and the destination.
A real exchange
This is curl 8.7.1 on macOS fetching https://example.com/ through a small logging proxy on localhost, with -v, trimmed to the lines that matter:
$ curl -sv -o /dev/null -x http://127.0.0.1:38519 https://example.com/
* Establish HTTP proxy tunnel to example.com:443
> CONNECT example.com:443 HTTP/1.1
> Host: example.com:443
> User-Agent: curl/8.7.1
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
<
* CONNECT tunnel established, response 200
* ALPN: curl offers h2,http/1.1
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF
* ALPN: server accepted h2
* using HTTP/2
Three details are worth reading closely. The request target is only example.com:443, which is the special form RFC 9110 reserves for this method, and the port is mandatory because CONNECT has no default. The tunnel was opened with HTTP/1.1, yet the request inside it went out as HTTP/2: ALPN was negotiated with the destination, through the tunnel, and the proxy took no part in that choice. And curl still sends Proxy-Connection: Keep-Alive, a header RFC 9112 encourages clients not to send at all, because it never worked once proxies were stacked in layers.
Compare plain HTTP through the same proxy. There is no tunnel. The client sends the whole URL in the request line, GET http://example.com/ HTTP/1.1, and the proxy reads, and can change, every header and byte.
What the proxy still learns
| Visible to the proxy | Hidden from the proxy |
|---|---|
| The destination hostname and port, from the CONNECT line | The URL path and query string |
| Byte counts in each direction, and the timing of every burst | Request and response headers |
| The TLS ClientHello, which crosses the tunnel unencrypted | Request and response bodies |
| Your address and your proxy credentials | Cookies and the site’s own authorisation tokens |
The third row surprises people. Relaying ciphertext does not mean seeing nothing: the ClientHello carries the server name and the cipher and extension lists that make up a client’s TLS fingerprint, and our ClientHello study shows how distinctive those are per library. The left column is enough to log which sites you visit, when and how much you transfer. To read the right column a proxy has to end your TLS session itself, which hands your client a different certificate; that is TLS interception, and certificate checks catch it.
Responses you will meet
- 200: the tunnel is open. RFC 9110 forbids
Content-LengthandTransfer-Encodingon a successful CONNECT response, and tells clients to ignore them if they appear. - 407: the proxy wants credentials. curl 8.7.1 reports it as
curl: (56) CONNECT tunnel failed, response 407, an exit code rather than a status, because the HTTPS request never started. From 8.20.0 the same failure exits with 7: curl’slib/cf-h1-proxy.creturnsCURLE_RECV_ERRORafter it in 8.19.0 andCURLE_COULDNT_CONNECTin 8.20.0. See proxy authentication. - 403: refused by policy. RFC 9110 says proxies should restrict CONNECT to a known set of ports, since an open tunnel to port 25 would let anyone relay spam through them, so a non-443 destination is a common trigger.
- 400: the port was empty or invalid, which RFC 9110 requires a server to reject.
- 502 or 504: the proxy could not reach the destination, or gave up waiting.
The status-code guide works through telling a proxy-side refusal from a site-side block when the cause is less obvious.
CONNECT in HTTP/2 and for UDP
In HTTP/2, RFC 9113 changes the shape without changing the idea: the tunnel takes over one stream instead of the whole connection, and the host and port travel in the :authority pseudo-header with no :scheme or :path. RFC 9298 extends the method to UDP, which lets an HTTP proxy carry QUIC, the transport under HTTP/3. Support for both varies by proxy, so check before assuming it.
For day-to-day use, the curl guide shows the flags that print this exchange, and HTTP_PROXY, HTTPS_PROXY and NO_PROXY explained covers why a client sometimes skips the proxy and never sends CONNECT at all.
Frequently asked questions
Why does HTTPS through a proxy need a special method?
Can a proxy see my HTTPS traffic after CONNECT?
Why does curl report an exit code instead of a 407?
Sources
- RFC 9110: HTTP Semantics, section 9.3.6, the CONNECT method
- RFC 9112: HTTP/1.1, appendix C.2.2 on the Proxy-Connection header
- RFC 9113: HTTP/2, section 8.5, the CONNECT method
- RFC 9298: Proxying UDP in HTTP
- curl 8.20.0 source, lib/cf-h1-proxy.c: CONNECT failure returns CURLE_COULDNT_CONNECT
- curl 8.19.0 source, lib/cf-h1-proxy.c: CONNECT failure returns CURLE_RECV_ERROR