From c67ad664ffacf614ba6716bab41ac2f18b0e880e Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Sat, 19 Oct 2024 13:33:40 +0800 Subject: [PATCH] fix(go): check for cloudflare proxy --- main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 735ac1d..a7305a7 100644 --- a/main.go +++ b/main.go @@ -40,11 +40,13 @@ Disallow: /harm/to/self func handleRequest(w http.ResponseWriter, r *http.Request, tmpl *template.Template) { sourceIP := func() string { + if r.Header.Get("CF-Connecting-IP") != "" { + return r.Header.Get("CF-Connecting-IP") + } if r.Header.Get("X-Forwarded-For") != "" { return r.Header.Get("X-Forwarded-For") - } else { - return strings.Split(r.RemoteAddr, ":")[0] } + return strings.Split(r.RemoteAddr, ":")[0] }() isHeadless := strings.HasPrefix(r.Header.Get("User-Agent"), "curl/")