From 1b49fff763c362a8beb8ec17fc9fd3d862d19316 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 18 Mar 2021 13:21:38 +0100 Subject: [PATCH] Fix Forwarded HTTP header handling "for" contains the port, if any. "port" doesn't exist. --- server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 0f8dcbe..c44f7df 100644 --- a/server.go +++ b/server.go @@ -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) }