Fix Forwarded HTTP header handling

"for" contains the port, if any. "port" doesn't exist.
This commit is contained in:
Simon Ser 2021-03-18 13:21:38 +01:00
parent 9046fda283
commit 1b49fff763

View File

@ -219,8 +219,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
forwarded := parseForwarded(req.Header)
forwardedHost := req.Header.Get("X-Forwarded-For")
forwardedPort := req.Header.Get("X-Forwarded-Port")
if forwarded["for"] != "" && forwarded["port"] != "" {
remoteAddr = net.JoinHostPort(forwarded["for"], forwarded["port"])
if forwarded["for"] != "" {
remoteAddr = forwarded["for"]
} else if forwardedHost != "" && forwardedPort != "" {
remoteAddr = net.JoinHostPort(forwardedHost, forwardedPort)
}