The Host Field in HTTP Request Headers
Recently came across a frontend question: “Is the Host field necessary when sending HTTP request headers?” I hadn’t paid much attention to this before, so I did some research and here’s a summary.
Is the Host Field Necessary?
Yes, it is necessary. For example, the same machine can have multiple hosts bound to the same port. In my blog server setup, I have domains like 1991421.cn
, en.1991421.cn
, etc., all bound to the same server. Without the Host field, the server wouldn’t know which specific host you’re trying to access.
Why You Don’t See Host in Chrome Network Tab
- Starting with HTTP/2, the
:authority
field is used instead of Host. - If you examine HTTP/1.1 requests, you can see the Host field.
When we check on the server side, we can usually use req.host
normally because frameworks typically abstract away the differences between these fields.
Related Resources
Final Thoughts
The Host header is indeed essential for modern web hosting where multiple domains share the same IP address and port. While HTTP/2 introduced the :authority
pseudo-header as a replacement, the underlying concept remains the same - identifying which specific host the client wants to communicate with on a shared server.