From 7405f66036537095b52c277d9b56969df33bfa57 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 5 Sep 2017 20:34:17 +0100 Subject: PLT-7519: Better rate-limiting. (#7365) --- utils/utils.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'utils/utils.go') diff --git a/utils/utils.go b/utils/utils.go index 89ea4377e..dd8bdb2a8 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "os" + "strings" "github.com/mattermost/platform/model" ) @@ -55,7 +56,15 @@ func RemoveDuplicatesFromStringArray(arr []string) []string { } func GetIpAddress(r *http.Request) string { - address := r.Header.Get(model.HEADER_FORWARDED) + address := "" + + header := r.Header.Get(model.HEADER_FORWARDED) + if len(header) > 0 { + addresses := strings.Fields(header) + if len(addresses) > 0 { + address = strings.TrimRight(addresses[0], ",") + } + } if len(address) == 0 { address = r.Header.Get(model.HEADER_REAL_IP) -- cgit v1.2.3-1-g7c22