2 回答
TA贡献1796条经验 获得超4个赞
来自go doc http.request:
type Request struct {
...
// For incoming requests, the Host header is promoted to the
// Request.Host field and removed from the Header map.
...
Header Header
...
// For server requests Host specifies the host on which the
// URL is sought. Per RFC 2616, this is either the value of
// the "Host" header or the host name given in the URL itself.
...
Host string
因此,r.Host不使用r.Header.Get("Host")
TA贡献1775条经验 获得超11个赞
尝试使用 r.Host?
文档说:
// For server requests Host specifies the host on which the URL
// is sought. Per RFC 7230, section 5.4, this is either the value
// of the "Host" header or the host name given in the URL itself.
那么也许试试看?
func index(w http.ResponseWriter, r *http.Request) {
if r.URL.Scheme != "https" {
http.Redirect(w, r, "https://"+r.Host+r.URL.Path, 301)
return
}
//....
}
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报