显式 HTTP 代理模式

最后更新: 2026-11-03 12:15:20 +0800 +0800
tags: Http | Proxy | TLS
原文以英文撰写。您正在阅读AI翻译版本。

代理比较 #

代理行为 ↓ / 客户端 → 代理跃点 →到代理使用 HTTP到代理使用 HTTPS
正向代理 — 客户端发送绝对形式请求,例如 GET http://target/path**优点:**最简单且支持广泛;代理可以对 HTTP 请求进行身份验证、缓存、过滤、路由和记录;协议开销低。**缺点:**客户端到代理的请求、标头、URL 和正文都是明文,除非目标载荷另有保护;跨不受信任的本地网络使用不安全。**优点:**加密客户端到代理的跃点,使本地网络无法看到代理凭据和 HTTP 请求细节;TLS 终止后,代理仍保留感知 HTTP 的能力。**缺点:**TLS 设置和 CPU 成本更高;代理仍能看到并修改请求内容;部署和配置不如 HTTP 代理 URL 普遍。
隧道代理 — 客户端发送 CONNECT host:port,然后传输字节流**优点:**通过代理访问 HTTPS 源站的标准且兼容性广泛的方式;端到端 TLS 仍保持在客户端与目标之间;代理通常无法检查 HTTP 载荷。**缺点:**客户端到代理跃点上的 CONNECT 请求及目标主机/端口是明文;代理流量可被观察,且可能被阻止或限制;没有 TLS 拦截时无法进行 HTTP 缓存或请求级策略控制。**优点:**同时加密 CONNECT 设置(包括代理身份验证和目标权限)以及隧道跃点;隧道内部使用 HTTPS 时,可以在不受信任的本地网络上提供分层保护。**缺点:**存在两层 TLS,设置开销更高;调试更困难,兼容性也略低;代理解密外层 TLS 后仍能观察连接元数据,策略仍主要停留在连接级别。

“到代理使用 HTTPS”表示通过 TLS 访问代理本身,例如 https://proxy.example:443 代理配置。它与目标站点是否使用 HTTPS 无关。

Example HTTP transcripts #

http
# Forward proxy over HTTP: these HTTP bytes are visible on the client-to-proxy hop.
Client -> proxy
GET http://origin.example/reports/42 HTTP/1.1
Host: origin.example
Proxy-Authorization: Basic <credentials>

Proxy -> client
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 11

{"ok":true}
http
# Forward proxy over HTTPS: the wire carries TLS records to proxy.example.
# After TLS decryption at the proxy, the HTTP exchange is:
Client -> proxy
GET http://origin.example/reports/42 HTTP/1.1
Host: origin.example
Proxy-Authorization: Basic <credentials>

Proxy -> client
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 11

{"ok":true}
http
# Tunnel proxy over HTTP: CONNECT headers are visible on the client-to-proxy hop.
Client -> proxy
CONNECT origin.example:443 HTTP/1.1
Host: origin.example:443
Proxy-Authorization: Basic <credentials>

Proxy -> client
HTTP/1.1 200 Connection Established

# Subsequent bytes are an end-to-end TLS session with origin.example;
# the origin HTTP requests are not exposed to the proxy.
http
# Tunnel proxy over HTTPS: the wire carries outer TLS records to proxy.example.
# After outer TLS decryption at the proxy, the HTTP exchange is:
Client -> proxy
CONNECT origin.example:443 HTTP/1.1
Host: origin.example:443
Proxy-Authorization: Basic <credentials>

Proxy -> client
HTTP/1.1 200 Connection Established

# Subsequent bytes carry an inner TLS session with origin.example inside the
# outer TLS connection; origin HTTP requests remain encrypted from the proxy
# and end-to-end to origin.example.

评论

在 GitHub 上阅读或评论(发表评论需要登录)