summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-10 15:42:27 +0000
committerGitHub <[email protected]>2020-05-10 15:42:27 +0000
commit87e88da7966baa000db04ab85aacea06823a22bc (patch)
treefb84b4c1aee83c655c683b7ae45673c5cb0da73c
parent4d7dff992d7aef6775744f91ce2766d164f4a5da (diff)
parentbd4601cf571a42ab18110d41f4977da6999ec12c (diff)
Merge #320
320: Add support of CloudFlare CF-Connecting-IP and True-Client-IP headers r=48d90782 a=vsychov Hi guys, this PR will add support of CF-Connecting-IP and True-Client-IP headers, that provided by cloudflare, in some cases it may be very useful - https://support.cloudflare.com/hc/en-us/articles/206776727-What-is-True-Client-IP- Co-authored-by: MichaelKo <[email protected]> Co-authored-by: Valery Piashchynski <[email protected]>
-rw-r--r--service/http/handler.go16
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"))
}
}