fix(go): check for cloudflare proxy

This commit is contained in:
Guanran Wang 2024-10-19 13:33:40 +08:00
parent 62df1e1401
commit c67ad664ff
Signed by: nyancat
GPG key ID: 91F97D9ED12639CF

View file

@ -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/")