Don't consider x-forwarded-port for the value of HTTP HOST

This commit is contained in:
Darren Shepherd 2020-04-01 15:03:05 -07:00
parent ccc92e7b19
commit 4645d8df16

View File

@ -3,7 +3,6 @@ package urlbuilder
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"net"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -22,29 +21,11 @@ func GetHost(r *http.Request, scheme string) string {
} }
host = strings.Split(r.Header.Get(ForwardedHostHeader), ",")[0] host = strings.Split(r.Header.Get(ForwardedHostHeader), ",")[0]
if host == "" { if host != "" {
host = r.Host
}
port := r.Header.Get(ForwardedPortHeader)
if port == "" {
return host return host
} }
if port == "80" && scheme == "http" { return r.Host
return host
}
if port == "443" && scheme == "http" {
return host
}
hostname, _, err := net.SplitHostPort(host)
if err != nil {
hostname = host
}
return strings.Join([]string{hostname, port}, ":")
} }
func GetScheme(r *http.Request) string { func GetScheme(r *http.Request) string {