为 js request 新增 remote ip

This commit is contained in:
ExplodingDragon
2025-11-25 21:22:14 +08:00
parent b89c868e73
commit 2471cbd87b
3 changed files with 3 additions and 4 deletions

View File

@@ -9,10 +9,6 @@ import (
// 注意,相关 ip 获取未做反向代理安全判断,可能导致安全降级
func GetRemoteIP(r *http.Request) string {
// 最先取 cloudflare 的头
if ip := r.Header.Get("CF-Connecting-IP"); ip != "" {
return ip
}
if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" {
ips := strings.Split(forwardedFor, ",")
if len(ips) > 0 {