HTTP 代理如何利用 HTTP 协议?代理 RFC?

发布于 2024-12-07 01:40:59 字数 88 浏览 0 评论 0原文

与实现 HTTP Web 服务器相比,如何实现 HTTP 代理?有什么区别?是否有关于此主题的明确指南或 RFC 或有用的书籍?

How does one go about implementing a HTTP proxy compared to implementing a HTTP webserver, what are the differences? Is there a definitive guide or RFC or a helpful book on this subject?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帅的被狗咬 2024-12-14 01:40:59

发送到代理的标头是不同的。

例如,以下是 Google Chrome 通过代理服务器发送到 www.baidu.com 的内容:

GET http://www.baidu.com/ HTTP/1.1
Host: www.baidu.com
Proxy-Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8

我们可以看到它是

GET http://www.baidu.com/ HTTP/1.1

而不是

GET / HTTP/1.1

,这里

Proxy-Connection: keep-alive

也是

Host: www.baidu.com

http 代理的 Host 字段是必需

对于 HTTPS 隧道代理:

CONNECT comet.zhihu.com:443 HTTP/1.1
Host: comet.zhihu.com:443
Proxy-Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36

我们可以看到

CONNECT comet.zhihu.com:443 HTTP/1.1

domain:443 而不是 https://domain

CONNECT字段将代理服务器变成类似TCP隧道的东西,然后将协议HTTPS替换为端口:443

对于socks5代理,事情变得很容易,因为socks5什么都不关心对于更高的协议,您只需告诉它主机和端口即可。

The header sent to a proxy is different.

For example, here is what is sent by Google Chrome to www.baidu.com via a proxy server:

GET http://www.baidu.com/ HTTP/1.1
Host: www.baidu.com
Proxy-Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8

We can see it is

GET http://www.baidu.com/ HTTP/1.1

instead of

GET / HTTP/1.1

and here is

Proxy-Connection: keep-alive

also

Host: www.baidu.com

Host field is required for http proxy.

For HTTPS tunnel proxy:

CONNECT comet.zhihu.com:443 HTTP/1.1
Host: comet.zhihu.com:443
Proxy-Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36

We can see

CONNECT comet.zhihu.com:443 HTTP/1.1

domain:443 instead of https://domain.

CONNECT field turn the proxy server to something like a TCP tunnel, then the protocol HTTPS is replaced by the port :443

For socks5 proxy, things become easy, because socks5 care nothing about higher protocol, you just tell it host and port.

嘿看小鸭子会跑 2024-12-14 01:40:59

代理与服务器非常相似;唯一的区别是,解析请求后,它只是转发请求并返回结果*,而不是处理请求本身。由于代理不必执行与普通服务器相同的处理量,因此它通常可以比完整的服务器对请求进行最少的解析,但除此之外它的想法是相同的。

*一些代理实现额外的缓存。有些还对响应/请求进行模糊处理,但这是邪恶的代理,希望您没有想到。

A proxy is very similar to a server; the only difference is that, after parsing the request, it merely forwards it and returns the result*, rather than processing the request, itself. Because the proxy does not have to do the same amount of processing as a normal server, it can often get away with a far more minimal parsing of the requests than a full-fleded server, but otherwise it is the same idea.

*Some proxies implement additional caching. Some also futz with the response/request, but that is the evil kind of proxy, which hopefully you do not have in mind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文