What Is HTTP CONNECT? How an HTTPS Proxy Tunnel Works

Published:

11 minute read

Acar Diveroli
Written by: Acar Diveroli
One tunnel with its side wall cut away: a proxy mouth reading the CONNECT line, blue encrypted bytes inside, 443 behind

HTTP CONNECT is the HTTP method a client uses to ask a proxy for a raw TCP tunnel to a specific host and port. The client sends CONNECT example.com:443, the proxy connects to the target and returns 200. From then on the proxy only carries bytes. The TLS handshake runs end to end between the client and the site. A common mix-up is treating an "HTTPS proxy" and an HTTPS target as the same thing. This post covers the tunnel steps, where authentication happens, the https:// proxy scheme and how to read curl output.

The four steps of the tunnel

A CONNECT tunnel is built in four steps, and only the first two lines are in a language the proxy understands. Everything after that is opaque bytes to the proxy.

  1. The client connects to the proxy and sends the line CONNECT example.com:443 HTTP/1.1. The request target is only host and port, with no path.
  2. The proxy opens a TCP connection to the target. If it succeeds, it returns HTTP/1.1 200 Connection established.
  3. The client starts the TLS handshake over the same connection. The site sends its certificate and the client verifies it.
  4. The encrypted HTTP request passes through the tunnel. The proxy relays bytes in both directions as they are.

This is the request our local test proxy logged:

http
CONNECT example.com:443 HTTP/1.1
Host: example.com:443
Proxy-Authorization: Basic dXNlcjpwYXNz
User-Agent: curl/8.22.0
Proxy-Connection: Keep-Alive

Under RFC 9110 the port is mandatory, and there is no default port. Any 2xx response means the connection switches to tunnel mode right after the response headers. Any other response means the tunnel did not open.

What the proxy sees in the tunnel

The proxy learns the target host and port from the CONNECT line, but it cannot read the request inside the tunnel. In our test the first bytes entering the tunnel started with 16 03 01. That is the marker of a TLS handshake record. There was no GET inside.

One detail is easy to miss. The first TLS message (ClientHello) carries the site name in plain text in the SNI field in most clients. In our test the name example.com was visible inside the first packet. So the proxy knows which site you visit, not which page you request.

WhatHTTPS target (CONNECT)HTTP target
Host and portVisibleVisible
Path and query (/test?q=1)HiddenVisible
Request headers, cookiesHiddenVisible
Page contentHiddenVisible

With an HTTP target there is no tunnel. The client writes the full address straight to the proxy: in our test the proxy logged the complete line GET http://example.com/test?q=1 HTTP/1.1. The only way to see inside the tunnel is to terminate TLS at the proxy and make the client trust the proxy's certificate. We cover that setup in our MITM proxy post.

Authentication and 407

Proxy credentials travel inside the CONNECT request, in the Proxy-Authorization header. Requests sent after the tunnel opens do not carry this header. In our test the GET / request inside the tunnel carried only Host, User-Agent and Accept.

If the credentials are missing or wrong, the proxy does not open the tunnel and returns 407 Proxy Authentication Required. The Proxy-Authenticate header in the response names the expected method. curl shows it like this:

text
> CONNECT example.com:443 HTTP/1.1
> Host: example.com:443
< HTTP/1.1 407 Proxy Authentication Required
< Proxy-Authenticate: Basic realm="test"
* CONNECT tunnel failed, response 407

A 407 always comes before the tunnel, and the site is not involved yet. curl 8.22.0 stopped with exit code 7 in this case. Check that the username and password are spelled correctly. If the password contains @, encode it as %40. Other causes are in our 407 error post.

Basic is not encryption. The value dXNlcjpwYXNz is the Base64 form of user:pass and decodes with a single command. If the connection between you and the proxy is plain TCP, this header can be read on the network.

HTTPS proxy vs HTTPS target

The phrase "HTTPS proxy" is used for two different things. The scheme in the proxy address sets the connection between you and the proxy. The scheme of the target URL sets the connection between you and the site.

Proxy addressTargetYou to proxyYou to site
http://…:8000https://Plain TCP, CONNECT readableTLS (in the tunnel)
http://…:8000http://Plain TCPUnencrypted
https://…https://TLSTLS (TLS inside TLS)

Most everyday use is the first row. As long as the target is HTTPS, the page content stays encrypted, even though the address starts with http://. The https:// proxy scheme adds a layer on top. The CONNECT line and the Proxy-Authorization header get encrypted too.

This scheme only works if the proxy endpoint speaks TLS. If your provider does not list a separate TLS endpoint, write the address with http://. In Proxynet examples the address looks like http://user:pass@pr.proxynet.io:8000. For traffic to HTTPS sites, this tunnel is the very flow described on the HTTPS Proxy page.

Client support

Not every client supports the https:// proxy scheme. For this post we tested only curl and Python Requests.

In curl, support shows up as the word HTTPS-proxy on the Features line of curl -V. curl 8.22.0 on Windows (Schannel) listed this feature. The command to our local test proxy listening on TLS was:

bash
curl -v \
  --proxy-cacert proxy-ca.pem \
  -x https://user:pass@localhost:18443 \
  https://example.com/

--proxy-cacert supplies a CA file to verify the proxy's certificate. With a self-signed certificate and without this option, curl stopped with code 60. --proxy-insecure turns verification off. Use it only for local testing.

Python Requests 2.34.2 (urllib3 2.6.3) worked with proxies={"https": "https://user:pass@localhost:18443"}. With the self-signed certificate we first got a ProxyError. Once we added the proxy's CA certificate to the bundle passed via verify=, the request returned 200. For Node, browsers and other libraries, check their own documentation. We did not test them for this post.

Port restrictions

RFC 9110 recommends that proxies supporting CONNECT limit its use to known ports. The reason is abuse: a tunnel to port 25 can turn the proxy into a relay for email spam. That is why some proxies configure CONNECT to allow only 443.

We set up our test proxy to allow only 443. For https://example.com:8443/ the proxy returned 403 Forbidden and curl printed CONNECT tunnel failed, response 403. The same happened with the -p (--proxytunnel) option. That option asks for a tunnel even for a plain HTTP target. The proxy rejected the CONNECT example.com:80 request as well.

If a target that works on 443 returns 403 on 8443, the problem is the port rule, not your credentials. Find out which ports your proxy provider allows. If the target service has an endpoint on 443, use that.

Troubleshooting

curl -v prints each step of the tunnel on its own line. * is a note from curl, > an outgoing line, < an incoming one.

curl line or codeMeaning
Establishing HTTP proxy tunnel to example.com:443CONNECT is about to be sent
CONNECT tunnel established, response 200Tunnel open, TLS starting
CONNECT tunnel failed, response 407Credentials missing or wrong
CONNECT tunnel failed, response 403Proxy does not accept this host or port
Exit code 60The https:// proxy's certificate could not be verified
Exit code 28https:// scheme pointed at a plain HTTP port
Exit code 56http:// scheme pointed at a TLS port

The last two rows are a mismatch between scheme and port. In our test, curl sending TLS to the plain port waited for a reply and timed out. curl sending plain CONNECT to the TLS port saw the connection reset.

If you see the response 200 line but the page never loads, the problem is not the tunnel but the TLS connection inside it or the target site. In a browser the same tunnel failure shows up as ERR_TUNNEL_CONNECTION_FAILED. The browser side is covered in our err_tunnel_connection_failed post.

How we tested

We ran the tests on December 1, 2026, on Windows 11. We used a local test proxy written in Python 3.13. The proxy required Basic authentication for user:pass, opened CONNECT only to 443, and logged each request line, its headers and the first bytes entering the tunnel. A copy of the same proxy listened on TLS with a self-signed certificate.

The clients were curl 8.22.0 (Schannel), shipped with Windows, and Python Requests 2.34.2 (urllib3 2.6.3). The target was example.com. Each scenario ran as a separate command.

The bottom line

For HTTPS targets, write the proxy address with http://; the client builds the tunnel itself. Use the https:// proxy scheme only if your provider gave you a TLS endpoint and your client supports it. Above all, check the response line in curl -v output first. 407, 403 and 200 point to three different problems. If you need an exit IP with location targeting, Residential Proxy works with the same CONNECT flow.

Sources

Frequently asked questions

What is HTTP CONNECT used for?

It lets you reach HTTPS sites through a proxy. The client asks the proxy for a TCP tunnel to a specific host and port. Once the proxy connects and returns 200, the client runs the TLS handshake directly with the site. From then on the proxy only relays encrypted bytes. The same method can carry other TCP protocols such as SSH, but some proxies limit this with a port rule.

Can a proxy see the content of my HTTPS traffic?

No, not in a normal CONNECT tunnel. The proxy sees the target host and port, plus the site name from the SNI field in the first TLS message. The path, query, headers, cookies and page content are encrypted. Seeing the content requires terminating TLS at the proxy. For that, the proxy's CA certificate has to be added to the certificates the client trusts.

Where in the tunnel does a 407 error happen?

Before the tunnel opens, as the response to the CONNECT request. If the proxy cannot find the Proxy-Authorization header or rejects the credentials, it returns 407 with a Proxy-Authenticate header. At this point no connection to the target site has been made. curl output shows the line CONNECT tunnel failed, response 407. Check the username, the password and the encoding of special characters in the password.

What is the difference between an HTTPS proxy and an HTTPS target?

One describes the link between you and the proxy, the other the link between you and the site. A proxy address starting with https:// means the connection to the proxy is also encrypted with TLS. An HTTPS target means the site speaks TLS. For an HTTPS target, the proxy address usually starts with http://. The page content still stays encrypted inside the tunnel.

Does curl support the https:// proxy scheme?

Yes, if it was built with the HTTPS-proxy feature. Check the Features line in the output of curl -V. curl 8.22.0 shipped with Windows listed this feature and worked in our test. Use --proxy-cacert to verify the proxy's certificate, and --proxy-insecure to turn verification off for local testing only. If the certificate cannot be verified, curl stops with code 60.

Why does CONNECT return 403 on ports other than 443?

Because the proxy enforces a port rule. RFC 9110 recommends that proxies supporting CONNECT limit its use to known ports. An unrestricted tunnel can turn the proxy into a relay for spam or other abuse. Some proxies allow only 443. If the target has an endpoint on 443, use it; otherwise ask your provider for the list of allowed ports.

Ask ChatGPTAsk Claude