X-Forwarded-For头和Via头的区别

8

我正在开发一个代理,并一直在研究头文件,观察W3指南。我的代理将传入的REMOTE-ADDR添加到X-FORWARDED-FOR头文件中,但我不确定这与Via头文件相比如何。我在维基百科页面上查看了相关信息,其中列出了:

Via: 1.0 fred, 1.1 example.com (Apache/1.1)

但是我没有找到任何关于如何构建它的说明。

1个回答

11
"They're both headers that indicate that content has passed through a proxy, and it's okay to include both headers.
The 'Via' header is used for indicating the protocol version (to determine if the connection was downgraded at any point), the hostname of the proxy, and an optional product/version of the proxy (similar to the 'User-Agent' of the proxy). It's mainly used for information/debugging or identifying and working around buggy proxies (e.g. if you wanted to use request pipelining, you'd monitor this space).
'XFF' is used for forwarding the original IP of the client to the server. If the server trusts the proxy (or chain of proxies), it can use this IP instead of the connection's IP."

所以,如果我将我的代理称为MyProxy,并且它的版本是1.0,但是经过了上面的示例,那么它将变成:Via: 1.0 fred, 1.1 example.com (Apache/1.1), 1.0 MyProxy。 - Mr Wilde
2
@MrWilde 抱歉,我忘记了该字段还携带其他信息。因此应该是 Via: …, 1.1 mrwildesserver (MyProxy/1.0)(其中1.1是您支持的HTTP版本)。 - Kornel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接