diff options
author | George Goldberg <george@gberg.me> | 2017-09-05 20:34:17 +0100 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-09-05 15:34:17 -0400 |
commit | 7405f66036537095b52c277d9b56969df33bfa57 (patch) | |
tree | e89223412cc560a51c5f4cdc6ff0c3816cc5b5f6 /utils/utils.go | |
parent | 09f8267751c71bdb6d8ba2757a1e4ffe62ccf5c3 (diff) | |
download | chat-7405f66036537095b52c277d9b56969df33bfa57.tar.gz chat-7405f66036537095b52c277d9b56969df33bfa57.tar.bz2 chat-7405f66036537095b52c277d9b56969df33bfa57.zip |
PLT-7519: Better rate-limiting. (#7365)
Diffstat (limited to 'utils/utils.go')
-rw-r--r-- | utils/utils.go | 11 |
1 files changed, 10 insertions, 1 deletions
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) |