690b7be1d8
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
21 lines
355 B
Go
21 lines
355 B
Go
package proxy
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
)
|
|
|
|
var xForwardedHost = http.CanonicalHeaderKey("X-Forwarded-Host")
|
|
|
|
func getHost(req *http.Request) string {
|
|
host := req.Host
|
|
if req.Header.Get(xForwardedHost) != "" {
|
|
host = req.Header.Get(xForwardedHost)
|
|
}
|
|
hostOnly, _, err := net.SplitHostPort(host)
|
|
if err != nil {
|
|
return host
|
|
}
|
|
return hostOnly
|
|
}
|