2
In an HTTP GET message, there is a HOST
field:
Host.
The domain name of the server (for virtual hosting), 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.
In this field, there is a port number. I know that port number is on the transport layer. So what is the port number in an HTTP GET message used for?
I understand the first 2 sentences. I don't understand :
If the web server needs to create an absolute URL back to itself, it can't use the transport layer information, because that'll just give it the internal network info. It needs to look at the HTTP headers to know what the real client is and how they are accessing the server to generate the URLs.
can you make it more clear? thanks – misteryes – 2013-05-29T23:05:04.090Besides, you said there are several things, how about the other useful things? – misteryes – 2013-05-29T23:05:29.810
@misteryes If the client is connecting to
http://ex.com:8080
, and that connection is being load-balanced over 3 webservers (int.ex.com:7001
,int.ex.com:7002
, andint.ex.com:7003
), then the webservers can't look at the transport layer to find out the port, because it will be incorrect. If a php script wants to write a link into a page, it can't just usehttp://int.ex.com:7001/somelink
. It needs to use theHost
field to do this, so that when the client clicks on it, they go to the correct url. – Darth Android – 2013-05-30T16:56:44.153so the TCP connection is just between the client and ex.com:80, there is no TCP connection between the client and ex.com:7001, ex.com:7002, is it right? – misteryes – 2013-05-31T15:49:41.410
Correct. There is a connection from the load balancer (on
ex.com:80
) andex.com:7001
, but not directly from the client toex.com:7001
. And most of the time, web pages use relative hyperlinks, so knowing the host/port is not a common issue, but it could be potentially. A much more common scenario is having the loadbalancer or proxy set theX-HTTPS
header, indicating if the client connected with https or not. Same concept- the webserver doesn't get to see the real client connection, so the proxy or load balancer has to make sure that the HTTP headers contain all of that information. – Darth Android – 2013-05-31T15:53:12.800