Browse Source

修复缺失方法

master v0.2.2
guzeng 3 years ago
parent
commit
e1611ccf47
1 changed files with 25 additions and 0 deletions
  1. +25
    -0
      site.go

+ 25
- 0
site.go View File

@ -99,3 +99,28 @@ func GetSiteInfoFromReq(master string, req *http.Request) (map[string]string, er
}
return siteInfo, nil
}
/**
* 取访问主机名
*/
func GetHost(req *http.Request) string {
var hostlist []string = req.Header.Values("X-Forwarded-Host")
var host string
if len(hostlist) > 1 {
host = hostlist[len(hostlist)-1] //取最后一次转发的
} else if len(hostlist) == 1 {
host = hostlist[0]
} else {
host = ""
}
if host != "" {
hosts := strings.Split(host, ",")
host = strings.Trim(hosts[len(hosts)-1], " ")
}
if host == "" {
host = req.Host
}
return host
}

Loading…
Cancel
Save