The main difference between HTTP/1.0 and HT开发者_如何学CTP/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?
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.
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).
精彩评论