Skip to content
Glossary

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.

Read the full guideHow to use curl with a proxy: flags, socks5h and errorscurl -x syntax for HTTP and SOCKS5 proxies, plus 15 proxy failures with the exact error curl 8.7.1 and 8.23.0 printed for…

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-Length and Transfer-Encoding on 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’s lib/cf-h1-proxy.c returns CURLE_RECV_ERROR after it in 8.19.0 and CURLE_COULDNT_CONNECT in 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?
Because the proxy cannot read an encrypted request to learn where to send it. CONNECT gives it the destination in plain text first, so it can open a raw tunnel and then relay bytes without interpreting them.
Can a proxy see my HTTPS traffic after CONNECT?
Not the contents. It sees the hostname and port, timing, byte counts and the unencrypted TLS ClientHello. Reading the contents would mean terminating TLS itself, which changes the certificate your client receives and is detectable.
Why does curl report an exit code instead of a 407?
Because the refusal came while opening the tunnel, before any HTTPS request existed to carry a status. curl prints 'CONNECT tunnel failed, response 407' and exits with 56 up to 8.19.0, and with 7 from 8.20.0. The same proxy answering a plain HTTP request returns an ordinary 407 response.

Sources

  1. RFC 9110: HTTP Semantics, section 9.3.6, the CONNECT method
  2. RFC 9112: HTTP/1.1, appendix C.2.2 on the Proxy-Connection header
  3. RFC 9113: HTTP/2, section 8.5, the CONNECT method
  4. RFC 9298: Proxying UDP in HTTP
  5. curl 8.20.0 source, lib/cf-h1-proxy.c: CONNECT failure returns CURLE_COULDNT_CONNECT
  6. curl 8.19.0 source, lib/cf-h1-proxy.c: CONNECT failure returns CURLE_RECV_ERROR

All terms, A to Z