The Host Field in HTTP Request Headers

The Host Field in HTTP Request Headers

3月 13, 2025 · 1 分钟阅读时长 · 210 字 · -阅读 -评论

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

  1. Starting with HTTP/2, the :authority field is used instead of Host.
  2. 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.

https://static.1991421.cn/2025/2025-03-13-182352.jpeg

https://static.1991421.cn/2025/2025-03-13-182439.jpeg

https://static.1991421.cn/2025/2025-03-13-182541.jpeg

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.

Alan H
Authors
开发者,数码产品爱好者,喜欢折腾,喜欢分享,喜欢开源