fix: 修复反向代理下客户端 IP 获取错误

This commit is contained in:
shaw
2026-01-12 20:44:38 +08:00
parent c206d12d5c
commit 22ef9534e0
4 changed files with 11 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ import (
"unicode/utf8"
"github.com/Wei-Shaw/sub2api/internal/pkg/ctxkey"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
@@ -522,7 +523,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
}
var clientIP string
if ip := strings.TrimSpace(c.ClientIP()); ip != "" {
if ip := strings.TrimSpace(ip.GetClientIP(c)); ip != "" {
clientIP = ip
entry.ClientIP = &clientIP
}
@@ -682,7 +683,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
}
var clientIP string
if ip := strings.TrimSpace(c.ClientIP()); ip != "" {
if ip := strings.TrimSpace(ip.GetClientIP(c)); ip != "" {
clientIP = ip
entry.ClientIP = &clientIP
}