File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff 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 () {
You can’t perform that action at this time.
0 commit comments