diff --git a/internal/middleware/security/ratelimit.go b/internal/middleware/security/ratelimit.go index c6058f1..730106d 100644 --- a/internal/middleware/security/ratelimit.go +++ b/internal/middleware/security/ratelimit.go @@ -339,7 +339,7 @@ func (rl *RateLimiter) getRetryAfter(key string) int64 { func keyByIP(ctx *fasthttp.RequestCtx) string { ip := netutil.ExtractClientIPNet(ctx) if ip == nil { - return "unknown" + return accessUnknown } return ip.String() } diff --git a/internal/server/testutil.go b/internal/server/testutil.go index 3311337..6ac7324 100644 --- a/internal/server/testutil.go +++ b/internal/server/testutil.go @@ -12,6 +12,9 @@ import ( "rua.plus/lolly/internal/ssl" ) +// testListenAddr 是测试用的随机端口监听地址 +const testListenAddr = "127.0.0.1:0" + // MockFastServer 是 fasthttp.Server 的 Mock 包装 // 定义在此文件以便 TestServerOptions 可以引用 type MockFastServer struct { @@ -108,7 +111,7 @@ func MustStartTestServer(cfg *config.Config) *Server { } if listenAddr == "" || listenAddr == ":80" { if len(cfg.Servers) > 0 { - cfg.Servers[0].Listen = "127.0.0.1:0" + cfg.Servers[0].Listen = testListenAddr } }