ソースを参照

use cloudflare ip

Tobias von Dewitz 5 年 前
コミット
f7fc968d86
1 ファイル変更4 行追加1 行削除
  1. 4 1
      setup.go

+ 4 - 1
setup.go

@@ -146,7 +146,10 @@ func getClientIP(r *http.Request, strict bool) (net.IP, error) {
 	var ip string
 
 	// Use the client ip from the 'X-Forwarded-For' header, if available.
-	if fwdFor := r.Header.Get("X-Forwarded-For"); fwdFor != "" && !strict {
+	if fwdFor := r.Header.Get("CF-Connecting-IP"); fwdFor != "" && !strict {
+		ips := strings.Split(fwdFor, ", ")
+		ip = ips[0]
+	} else if fwdFor := r.Header.Get("X-Forwarded-For"); fwdFor != "" && !strict {
 		ips := strings.Split(fwdFor, ", ")
 		ip = ips[0]
 	} else {