0

I'm aware of how HOST header can help us having multiple websites on a single IP address. In HOST header, we can optionally specify "port number". (80 by default for HTTP)

In OSI model, layer-4 is responsible for dealing with "ports" and after reassembling the packets, it can hand them to the correct application/process.

On the other hand, HTTP works in layer-7 of OSI. So on that point, I think the application already received the correct packet and knows the port number.

Then why the HOST header have this "port number" part and how can this "port" of HOST header help us?

Also I want to know that if they are different or can be different ?

1 Answer 1

1

The port in the URL is the same port that gets used for the TCP connection and it is the same port that's in the host header.

The protocol is kind of Layer 5/6 but definitely not Layer 7. You might be able to argue it is Layer 6, but probably not if it's encrypted, in which case TLS would be l5 and http l6.

Adding the port allows the session layer to instruct the OS what port to use.

For some L5 protocols the application knows the default port, eg http(80) https(443) ftp(21).

But when you want to run one of those L5 sessions over a different L4 connection the user needs a way to instruct the TCP stack to do this. So the designers of http decided to allow an optional TCP port at the end of the URL.

The port in the host header tells you which endpoint your clients connected to. Eg abc.com:80 and abc.com:81 are different Endpoints, but they could be connected to the same server instance.

While it's true that a server can work out which port a user is connected to by looking at the socket, the server implementation might not support this or it might be necessary to retain it in the future.

If your server needs the port on the host header becomes a question of implementation and needs.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer, According to wikipedia I thought HTTP is L7. "The port in the host header tells you which endpoint your clients connected to" so if I got you correctly you mean first webserver gets the request on 80 or 443 then it can decide to send the request to whatever processing application it wants according to the port number specified in HOST header ?
Or with our specific implementation we can have an application which redirects requests to other processes in the server, again according to the port number in HOST header.
You can use the host header however you want. Be aware that there is no hard implementation for adding the port. Some older browsers will not add the port to the host header, others will.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.