diff options
author | Wolfy-J <[email protected]> | 2020-05-19 15:17:41 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2020-05-19 15:17:41 +0300 |
commit | c3c7165bf4dd5a9929f506c25ccf5d41c7b69c83 (patch) | |
tree | f7b632e8b9c3151e985ef9361077942af9c074b3 /service | |
parent | 5b6269f1f505bd3ebda676a9e9c90f7b346deb78 (diff) | |
parent | 5600d806fbc0339d629501b45b09f8fc7f64e260 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'service')
-rw-r--r-- | service/http/handler.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/service/http/handler.go b/service/http/handler.go index 3c667035..ab7c382b 100644 --- a/service/http/handler.go +++ b/service/http/handler.go @@ -175,7 +175,23 @@ func (h *Handler) resolveIP(r *Request) { return } + // The logic here is the following: + // In general case, we only expect X-Real-Ip header. If it exist, we get the IP addres from header and set request Remote address + // But, if there is no X-Real-Ip header, we also trying to check CloudFlare headers + // True-Client-IP is a general CF header in which copied information from X-Real-Ip in CF. + // CF-Connecting-IP is an Enterprise feature and we check it last in order. + // This operations are near O(1) because Headers struct are the map type -> type MIMEHeader map[string][]string if r.Header.Get("X-Real-Ip") != "" { r.RemoteAddr = fetchIP(r.Header.Get("X-Real-Ip")) + return + } + + if r.Header.Get("True-Client-IP") != "" { + r.RemoteAddr = fetchIP(r.Header.Get("True-Client-IP")) + return + } + + if r.Header.Get("CF-Connecting-IP") != "" { + r.RemoteAddr = fetchIP(r.Header.Get("CF-Connecting-IP")) } } |