Skip to content

Commit 99c6527

Browse files
committed
Merge branch 'ip-determine'
2 parents e36b06f + 5801958 commit 99c6527

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/server/server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ func (s *Server) handler(ctx *fasthttp.RequestCtx) {
9494

9595
var err error
9696
remoteIP := string(ctx.Request.Header.Peek(http.CanonicalHeaderKey("X-Forwarded-For")))
97-
if len(remoteIP) > 0 {
97+
98+
// If X-Forwarded-For is empty, fallback to ctx.RemoteIP()
99+
if remoteIP == "" {
100+
remoteIP = ctx.RemoteIP().String()
101+
}
102+
103+
if remoteIP != "" {
98104
isBlocked := s.RedisClient.CheckBlacklist(remoteIP)
99105
if isBlocked {
100106
ctx.Error("Too Many Requests", fasthttp.StatusTooManyRequests)
@@ -106,7 +112,7 @@ func (s *Server) handler(ctx *fasthttp.RequestCtx) {
106112
log.Errorf("failed to increment IP in database: %s", err.Error())
107113
}
108114
} else {
109-
log.Errorf("failed to get remote IP")
115+
log.Errorf("failed to determine remote IP")
110116
}
111117

112118
defer func() {

0 commit comments

Comments
 (0)