Adjusting how we handle IP address parsing to more gracefully handle X-Forwarded-For headers. Ref #1999

pull/2060/head
Jordan Wright 2020-10-14 20:35:32 -05:00
parent 120e232cfe
commit 8b8e88b077
1 changed files with 1 additions and 6 deletions

View File

@ -360,12 +360,7 @@ func setupContext(r *http.Request) (*http.Request, error) {
} }
ip, _, err := net.SplitHostPort(r.RemoteAddr) ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil { if err != nil {
log.Error(err) ip = r.RemoteAddr
return r, err
}
// Respect X-Forwarded headers
if fips := r.Header.Get("X-Forwarded-For"); fips != "" {
ip = strings.Split(fips, ", ")[0]
} }
// Handle post processing such as GeoIP // Handle post processing such as GeoIP
err = rs.UpdateGeo(ip) err = rs.UpdateGeo(ip)