fix: parsing of ip address (#2045)

This commit is contained in:
Livio Amstutz 2021-07-20 10:10:48 +02:00 committed by GitHub
parent 6ff434e853
commit 9413fc19ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,7 +77,8 @@ func RemoteIPStringFromRequest(r *http.Request) string {
if ok {
return ip
}
return r.RemoteAddr
host, _, _ := net.SplitHostPort(r.RemoteAddr)
return host
}
func GetAuthorization(r *http.Request) string {
@ -91,7 +92,7 @@ func GetOrgID(r *http.Request) string {
func GetForwardedFor(headers http.Header) (string, bool) {
forwarded, ok := headers[ForwardedFor]
if ok {
ip := strings.Split(forwarded[0], ", ")[0]
ip := strings.TrimSpace(strings.Split(forwarded[0], ",")[0])
if ip != "" {
return ip, true
}