2021-04-23 13:07:44 +01:00
|
|
|
package proxy
|
|
|
|
|
2021-05-11 19:02:36 +01:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
)
|
2021-04-23 13:07:44 +01:00
|
|
|
|
|
|
|
var xForwardedHost = http.CanonicalHeaderKey("X-Forwarded-Host")
|
|
|
|
|
|
|
|
func getHost(req *http.Request) string {
|
2021-05-11 19:02:36 +01:00
|
|
|
host := req.Host
|
2021-04-23 13:07:44 +01:00
|
|
|
if req.Header.Get(xForwardedHost) != "" {
|
2021-05-11 19:02:36 +01:00
|
|
|
host = req.Header.Get(xForwardedHost)
|
2021-04-23 13:07:44 +01:00
|
|
|
}
|
2021-05-11 19:02:36 +01:00
|
|
|
hostOnly, _, err := net.SplitHostPort(host)
|
|
|
|
if err != nil {
|
|
|
|
return host
|
|
|
|
}
|
|
|
|
return hostOnly
|
2021-04-23 13:07:44 +01:00
|
|
|
}
|