File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,13 @@ import (
88 "strings"
99)
1010
11+ var trueClientIP = http .CanonicalHeaderKey ("True-Client-IP" )
1112var xForwardedFor = http .CanonicalHeaderKey ("X-Forwarded-For" )
1213var xRealIP = http .CanonicalHeaderKey ("X-Real-IP" )
1314
1415// RealIP is a middleware that sets a http.Request's RemoteAddr to the results
15- // of parsing either the X-Real-IP header or the X-Forwarded-For header (in that
16- // order).
16+ // of parsing either the True-Client-IP, X-Real-IP or the X-Forwarded-For headers
17+ // (in that order).
1718//
1819// This middleware should be inserted fairly early in the middleware stack to
1920// ensure that subsequent layers (e.g., request loggers) which examine the
@@ -40,7 +41,9 @@ func RealIP(h http.Handler) http.Handler {
4041func realIP (r * http.Request ) string {
4142 var ip string
4243
43- if xrip := r .Header .Get (xRealIP ); xrip != "" {
44+ if tcip := r .Header .Get (trueClientIP ); tcip != "" {
45+ ip = tcip
46+ } else if xrip := r .Header .Get (xRealIP ); xrip != "" {
4447 ip = xrip
4548 } else if xff := r .Header .Get (xForwardedFor ); xff != "" {
4649 i := strings .Index (xff , ", " )
You can’t perform that action at this time.
0 commit comments