summaryrefslogtreecommitdiffstats
path: root/utils/utils.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-09-05 20:34:17 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2017-09-05 15:34:17 -0400
commit7405f66036537095b52c277d9b56969df33bfa57 (patch)
treee89223412cc560a51c5f4cdc6ff0c3816cc5b5f6 /utils/utils.go
parent09f8267751c71bdb6d8ba2757a1e4ffe62ccf5c3 (diff)
downloadchat-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.go11
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)