Skip to content

Commit

Permalink
Update to get real IP from X-Real-IP as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
kakaLQY committed Jul 3, 2017
1 parent 2da913e commit f326494
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions lg.go
Expand Up @@ -74,9 +74,14 @@ func LogRequest(next http.Handler) http.Handler {
lw := &basicWriter{ResponseWriter: w}

// Get the real IP even behind a proxy
realIP := r.Header.Get("X-Forwarded-For")
if len(realIP) == 0 {
realIP = r.RemoteAddr
realIP := r.Header.Get(http.CanonicalHeaderKey("X-Forwarded-For"))
if realIP == "" {
// if no content in header "X-Forwarded-For", get "X-Real-IP"
if xrip := r.Header.Get(http.CanonicalHeaderKey("X-Real-IP")); xrip != "" {
realIP = xrip
} else {
realIP = r.RemoteAddr
}
}

// Process request
Expand Down

0 comments on commit f326494

Please sign in to comment.