File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -225,15 +225,16 @@ func extractIP(req *http.Request) string {
225225func ExtractIPFromRealIPHeader (options ... TrustOption ) IPExtractor {
226226 checker := newIPChecker (options )
227227 return func (req * http.Request ) string {
228+ remoteIP := extractIP (req )
228229 realIP := req .Header .Get (HeaderXRealIP )
229- if realIP != "" {
230- realIP = strings .TrimPrefix (realIP , "[ " )
231- realIP = strings . TrimSuffix ( realIP , "]" )
232- if ip := net .ParseIP (realIP ); ip != nil && checker . trust ( ip ) {
230+ realIP = strings . TrimPrefix ( realIP , "[" )
231+ realIP = strings .TrimSuffix (realIP , "] " )
232+ if checker . trust ( remoteIP ) && realIP != "" {
233+ if ip := net .ParseIP (realIP ); ip != nil {
233234 return realIP
234235 }
235236 }
236- return extractIP ( req )
237+ return remoteIP
237238 }
238239}
239240
You can’t perform that action at this time.
0 commit comments