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

标签 http go httprequest virtualhost virtual-hosts

我正在打印所有标题,我得到:

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.

这样就可以通过access获取host了

http.Request.Host

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

关于http - 为什么我的 http 请求 header 字段中缺少主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37096166/

相关文章:

service - 如何在istio虚拟服务头精确匹配中使用OR逻辑?

http - http中post数据的最大大小

json - Elixir Plug.Parsers.JSON 的访问结果

go - 如何在golang中测试http.Redirect目标URL

Android 数据库 - 没有这样的表错误

spring - 如何在 Spring WebFilter 中添加自定义 header ?

java - 更正 CacheControl 配置以指示不应缓存资源表示?

php - ssl 证书导致一个文件不工作

mongodb - 使用 mongo-driver 进行 Golang mongodb 聚合

go - 从 golang 的 exec.Command 调用 ghostscrip 时出错