Reputation: 29
GET /calcuapp/calculator.jsp HTTP/1.1
Host: 192.168.1.66:8080
I'm using PuTTy and the host destination is already set up on the settings. Why do I need again to type the host destination as you can see above?
Upvotes: 1
Views: 5926
Reputation: 189387
Your local resolver (DNS etc) converts the host name on the command line to an IP address before connecting; there is no way for the remote server to know which host name you gave on the command line if there are multiple host names which resolve to the same IP address (this is what's called "virtual hosting"; with HTTP 1.0, you needed a separate IP address for each distinct HTTP host, which is extremely wasteful, but saves you from needing to transmit the Host:
header).
Upvotes: 0
Reputation: 130907
The Host
HTTP header is mandatory since HTTP/1.1 and it's used for virtual hosting.
It must include the domain name of the server, and the TCP port number on which the server is listening. The port number may be omitted if the port is the standard port for the service requested (80
for HTTP and 443
for HTTPS).
A HTTP/1.1 request that lacks the Host
header should be responded with a 400
(Bad Request) status code.
The RFC 7230, the current reference message syntax and routing in HTTP/1.1, tells the whole story about this header:
The
Host
header field in a request provides the host and port information from the target URI, enabling the origin server to distinguish among resources while servicing requests for multiple host names on a single IP address.Host = uri-host [ ":" port ]
A client MUST send a
Host
header field in all HTTP/1.1 request messages. If the target URI includes an authority component, then a client MUST send a field-value forHost
that is identical to that authority component, excluding any userinfo subcomponent and its@
delimiter. If the authority component is missing or undefined for the target URI, then a client MUST send aHost
header field with an empty field-value.Since the
Host
field-value is critical information for handling a request, a user agent SHOULD generateHost
as the first header field following the request-line.For example, a GET request to the origin server for
http://www.example.org/pub/WWW/
would begin with:GET /pub/WWW/ HTTP/1.1 Host: www.example.org
A client MUST send a
Host
header field in an HTTP/1.1 request even if the request-target is in the absolute-form, since this allows theHost
information to be forwarded through ancient HTTP/1.0 proxies that might not have implementedHost
.When a proxy receives a request with an absolute-form of request-target, the proxy MUST ignore the received
Host
header field (if any) and instead replace it with the host information of the request-target. A proxy that forwards such a request MUST generate a newHost
field-value based on the received request-target rather than forward the receivedHost
field-value.Since the
Host
header field acts as an application-level routing mechanism, it is a frequent target for malware seeking to poison a shared cache or redirect a request to an unintended server. An interception proxy is particularly vulnerable if it relies on theHost
field-value for redirecting requests to internal servers, or for use as a cache key in a shared cache, without first verifying that the intercepted connection is targeting a valid IP address for that host.A server MUST respond with a
400
(Bad Request) status code to any HTTP/1.1 request message that lacks aHost
header field and to any request message that contains more than oneHost
header field or aHost
header field with an invalid field-value.
Upvotes: 2
Reputation: 16331
The short answer is Virtual Hosts.
For many years now, it has been quite common to host multiple sites/domains from a single server. HTTP 1.1 supports this by requiring the host
header. If you use HTTP 1.0 you may leave this out.
Upvotes: 3