Why does Wget have Host Header in its HTTP request?

隐身守侯 提交于 2019-12-24 00:28:47

问题


The main difference between HTTP/1.0 and HTTP/1.1 is that HTTP/1.1 has a mandatory Host header in it (source: HTTP Pocket Reference - O'reilly).

So, why is that Wget, which uses the HTTP/1.0 protocol, has a host header in it?

My output of Wget with netcat:

GET / HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */*
Host: 127.0.0.1:10101
Connection: Keep-Alive

As it is clear that Wget uses the HTTP/1.0 protocol version, how can it have a host header in it? Or am I getting somewhere wrong with my understanding of HTTP protocol?

And even if HTTP/1.0 can has Host Header in its HTTP request, what can be the reason behind wget using HTTP/1.0 protocol while HTTP/1.1 can also be used in place of that?


回答1:


The Host header was added as an "optional" addition to HTTP/1.0 very early on when it was realized this was the only way to allow one server to serve up pages for multiple domains. wget uses HTTP/1.0 with Host as the way to be compatible with the maximum number of sites, some of which don't respond to HTTP/1.1 even though they require Host.




回答2:


In HTTP/1.0, the Host header was optional. The difference is that HTTP/1.1 changed it from optional to mandatory.

In particular, if the GET line doesn't include the hostname (like in your example), you need to include it in the headers (because otherwise, "virtual" domains would not be possible if the server cannot determine which host your request was for).



来源:https://stackoverflow.com/questions/4032412/why-does-wget-have-host-header-in-its-http-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!