为什么我的 http 请求 header 字段中缺少主机?

why is host missing from my http request header fields?

我正在打印所有 headers,我得到:

map[Cookie:[_ga=GA1.2.843429125.1462575405] User-Agent:[Mozilla/5.0
(Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko)
Version/9.0.3 Safari/601.4.4] Accept-Language:[en-us] 
Accept-Encoding:[gzip, deflate] Connection:[keep-alive] 
Accept:[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]]

这意味着我的浏览器正在发送 "Cookie"、"User-Agent"、"Accept-Language"、"Accept-Encoding"、"Connection" 和 "Accept",但是有没有 "Host" 值。

如何在没有此值的情况下让我的 https://en.wikipedia.org/wiki/Virtual_hosting 工作?

我正在使用 https://github.com/gin-gonic/gin

它在 Golang http 文档中声明:

For incoming requests, the Host header is promoted to the Request.Host field and removed from the Header map.

这样就可以通过访问获取主机

http.Request.Host

点击这里了解详情:https://golang.org/pkg/net/http/