How Does a Proxy Handle HTTP and HTTPS? The Two Flows

Published:

11 minute read

Acar Diveroli
Written by: Acar Diveroli
Two lanes leave a proxy gate: the http lane shows an open request sign, the https lane a blue capsule showing only host:443

The scheme of the target URL decides how a proxy carries a request. For an http:// target, the client sends the full URL to the proxy and the proxy reads the whole request. For an https:// target, the client asks for a tunnel with CONNECT and the proxy sees only the server name and port. The trap is on the error side: the same 407 arrives as an ordinary response on one target and as a connection error on the other. This post covers both flows, where the credentials go, the stage at which errors appear and how the curl output differs.

The two flows side by side

Even with the same proxy address, the client sends two different requests depending on the target. For a plain HTTP target it sends the request itself, for an HTTPS target a tunnel request. Everything the proxy can see and do follows from this split.

Topichttp:// targethttps:// target
First line sent to the proxyGET http://site/path?x=1CONNECT site:443
Path, query, headers, bodyProxy reads themProxy can't see them
Adding headers, cachingPossibleNot possible
Proxy-AuthorizationOn every requestOnly on CONNECT
How a proxy error arrivesAs an HTTP responseThe tunnel fails to open

We recorded every row of the table with a local test proxy, shown below. The proxy wrote each incoming line and header to a file. The target site logged the request that reached it.

Plain HTTP: the full URL goes to the proxy

For an http:// target, the client writes the full URL in the request line instead of the path. The HTTP/1.1 standard calls this "absolute-form" and requires it for requests sent to a proxy. The proxy reads the line, connects to the target itself and forwards the request in the short path form.

In curl's -v output, the lines the client sends start with >:

bash
curl -v -x http://user:pass@pr.proxynet.io:8000 \
  "http://shop.test/product?id=42"
text
> GET http://shop.test/product?id=42 HTTP/1.1
> Host: shop.test
> Proxy-Authorization: Basic dXNlcjpwYXNz
> User-Agent: curl/8.23.0
< HTTP/1.1 200 OK

The target site's log looked like this:

text
GET /product?id=42 HTTP/1.1
host: shop.test
user-agent: curl/8.23.0
via: 1.1 test-proxy

Two details stand out. The proxy removed the Proxy-Authorization header before forwarding, so the site never saw the password. The Via header our test proxy added did reach the site. Because the proxy can read a plain HTTP request, it can add headers, cache the response or block a URL. We cover what a proxy can see in a wider table in What Is an HTTP Proxy?

HTTPS: the proxy sees only the address

For an https:// target, the client first sends CONNECT site:443. This line has no path, query or headers, only the server name and port. Once the proxy returns 200, the connection becomes a tunnel and the client runs the TLS handshake inside it, directly with the site.

When we requested the same address with https://, the curl output split into two stages:

text
* Establishing HTTP proxy tunnel to shop.test:443
> CONNECT shop.test:443 HTTP/1.1
> Host: shop.test:443
> Proxy-Authorization: Basic dXNlcjpwYXNz
< HTTP/1.1 200 Connection established
* CONNECT tunnel established, response 200
> GET /product?id=42 HTTP/1.1
> Host: shop.test
< HTTP/1.1 200 OK

The first block is the conversation with the proxy. The second block is the encrypted request passing through the tunnel. curl shows the second one decrypted because it sets up TLS itself. The proxy's log held only the CONNECT shop.test:443 line and byte counts. The first bytes through the tunnel started with 16 03 01. That is the first record of the TLS handshake. Later requests and responses are encrypted with the keys agreed in that handshake.

The request that reached the site had no Via header. The proxy can't touch the encrypted stream, so it can't add headers or cache the response. Proxynet HTTPS Proxy traffic to https:// sites also goes through this tunnel.

Where Proxy-Authorization goes

Proxy-Authorization is meant only for the proxy and is not forwarded to the site. RFC 9110 defines it as a header consumed by the first proxy that asked for credentials. The difference lies in how often the header is sent.

We sent two requests to the same site and checked the proxy log:

FlowWhat the proxy sawCredentials sent
http://, two requestsTwo separate GET http://… linesTwice
https://, two requestsOne CONNECT lineOnce

In plain HTTP, every request is a separate message to the proxy and carries the header itself. In HTTPS, the credentials are checked once while the tunnel is set up. As long as the tunnel stays open, the requests inside it don't resend the password.

One more warning. If the proxy address starts with http://, both the CONNECT line and the header travel to the proxy in plain text. The value dXNlcjpwYXNz is not encryption, it is the Base64 encoding of user:pass. On a shared network, consider IP whitelist authentication, which sends no password.

The stage where errors appear

An error generated by the proxy arrives as an ordinary response in plain HTTP. In HTTPS, the tunnel never opens and the client treats this as a connection error. So where your code catches the error depends on the target's scheme.

We produced a 407 with a wrong password and a 502 with a nonexistent domain:

CasecurlRequestsHTTPX
407, http://Response 407, exit code 0status_code == 407status_code == 407
407, https://CONNECT tunnel failed, response 407, exit 7ProxyErrorProxyError
502, http://Response 502, exit code 0status_code == 502status_code == 502
502, https://CONNECT tunnel failed, response 502, exit 7ProxyErrorProxyError

The Requests message for HTTPS was exactly Tunnel connection failed: 407 Proxy Authentication Required. In plain HTTP, no exception was raised. A script that only has try/except ProxyError can mistake a 407 on an http:// target for a successful response. Check the status code separately in both flows. Our HTTP 407 guide goes through the possible causes one by one.

The stage also tells you where a 502 came from. In HTTPS, a 502 that arrives after the tunnel is up comes from the target site or a server in front of it, not from the proxy. In plain HTTP, both sources look the same. To tell them apart, check the response body and headers.

The target scheme picks the proxy setting

Clients also decide which proxy to use by looking at the target's scheme. In Requests, the http key of the proxies dictionary applies to http:// targets and the https key to https:// targets. The HTTP_PROXY and HTTPS_PROXY environment variables make the same split.

python
import requests

proxy = "http://user:pass@pr.proxynet.io:8000"
# Wrong: only the http key, https targets go direct
proxies = {"http": proxy}
# Right: both schemes use the same proxy
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://example.com/", proxies=proxies, timeout=15)
print(r.status_code)

In our test, the script with only the http key never asked the proxy about the https:// target. It tried to resolve the name itself and failed. On a real site this error doesn't appear: the request quietly goes out from your own IP. The value of both keys starts with http://. That value tells the client how to talk to the proxy, not the target's scheme.

Troubleshooting

The first > line in curl's output tells you which flow you're in. If you see > GET http://…, you're in the plain flow. If you see > CONNECT host:443, a tunnel is being opened. To tell who produced an error, curl can print the two codes separately:

bash
curl -s -o /dev/null -x http://user:pass@pr.proxynet.io:8000 \
  -w "site=%{http_code} proxy=%{http_connect}\n" \
  https://example.com/

http_connect is the code the proxy returned to the CONNECT request. http_code is the final response from the site. In our test, a wrong password gave site=000 proxy=407. The same attempt on an http:// target gave site=407 proxy=000. A quick reading rule:

  • If proxy= is not 200, the problem is on the proxy side: credentials, quota or the connection to the target.
  • If proxy=200 and site= shows an error code, the tunnel opened and the site returned the error.
  • If proxy=000, either the target is http:// or the request never reached the proxy. Check the -v output.

Other options for using a proxy with curl are in our cURL with a proxy post.

How we tested

We ran the tests on December 1, 2026, on Windows 11. We used curl 8.23.0, Node.js 24.22.2, Python 3.13.17, Requests 2.34.2 and HTTPX 0.28.1. We ran a small Node.js proxy on 127.0.0.1. It required Basic authentication, logged every incoming line and header, and added Via to plain HTTP requests.

The target was a local server. The proxy pointed the name shop.test at that server. The HTTPS side used a self-signed certificate, so we passed -k to curl in the test only. Don't use -k against a real site. For the 502, we requested the nonexistent domain missing.invalid. In the commands in this post we wrote pr.proxynet.io:8000 instead of the local address.

The bottom line

Read which flow you're in from the first line of the -v output, and catch proxy errors separately in both flows. Write both schemes into the proxies dictionary or the environment variables. Above all, don't assume you caught a 407 just because you wrote try/except: in plain HTTP it is a response. You can try the setup against both targets with a Residential Proxy address.

Sources

Frequently asked questions

Can a proxy see the page I visit on an HTTPS site?

No, as long as your client verifies the site's certificate. The proxy sees only the server name and port in the CONNECT line, plus the amount of data transferred and the timing. The path, query, cookies and page content travel encrypted inside the tunnel. A tool that ignores certificate errors, or a foreign root certificate installed on the device, removes this protection.

Should the proxy address start with https:// for an HTTPS target?

No. The scheme of the proxy address describes how to talk to the proxy, not the target. The address http://user:pass@pr.proxynet.io:8000 also works for https:// sites: the client opens a CONNECT tunnel through it. Write an https:// proxy address only if the proxy itself speaks TLS. Point it at a port that speaks plain HTTP and the TLS handshake never completes.

Can the target site see my proxy password?

No. The Proxy-Authorization header is for the proxy only. In plain HTTP, the proxy reads the header, removes it and then forwards the request to the site. In HTTPS, the header goes only with the CONNECT request and is never added to the requests inside the tunnel. In our test, the site's log had no such header in either flow. An Authorization header sent to the site is a separate thing and unrelated to the proxy.

Why does a 407 arrive as an error on https:// but as a response on http://?

Because in HTTPS the 407 is returned to the CONNECT request, before the tunnel exists. The client can't open the tunnel, never reaches the site and treats this as a connection error. curl prints CONNECT tunnel failed, Requests and HTTPX raise ProxyError. In plain HTTP, the 407 is an ordinary response to the request itself and shows up in status_code.

Can a proxy cache responses from https:// sites?

No, not in tunnel mode. To cache a response, the proxy has to be able to read it, but traffic after CONNECT is encrypted end to end. In plain HTTP, the proxy sees the response and can store it according to caching rules. That is why caching corporate proxies can inspect HTTPS traffic only by stepping in with their own certificate, which means opening up the TLS.

How do I tell which flow I'm in from curl -v output?

Look at the first > line. A > GET http://site/path line is the plain HTTP flow, and the proxy reads the entire request. A > CONNECT site:443 line followed by the CONNECT tunnel established message is the tunnel flow. In the tunnel flow a second > GET /path block appears. curl prints it decrypted, but the proxy sees the same request encrypted.

Ask ChatGPTAsk Claude