Skip to content

Commit 7c79d69

Browse files
authored
Merge pull request #4 from aleksasiriski/patch-1
Improve comment and logic for real IP handling
2 parents f0c86aa + f452b61 commit 7c79d69

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

real_ip.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,12 @@ func (r *RealIPOverWriter) ServeHTTP(rw http.ResponseWriter, req *http.Request)
6565
}
6666
}
6767

68-
// Use `Cf-Connecting-Ip` when available
68+
// Use `Cf-Connecting-Ip` when available, otherwise use X-Real-Ip if available
6969
if req.Header.Get(cfConnectingIP) != "" {
7070
realIP = req.Header.Get(cfConnectingIP)
7171
req.Header.Set(xForwardedFor, realIP)
7272
req.Header.Set(xRealIP, realIP)
73-
}
74-
75-
if req.Header.Get(xRealIP) == "" {
73+
} else if req.Header.Get(xRealIP) == "" {
7674
realIP = req.RemoteAddr
7775
req.Header.Set(xRealIP, realIP)
7876
}

0 commit comments

Comments
 (0)