summary refs log tree commit diff stats
path: root/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'http.go')
-rw-r--r--http.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/http.go b/http.go
index 98e0cb5..fcce0a7 100644
--- a/http.go
+++ b/http.go
@@ -10,7 +10,7 @@ import (
 
 // Attaches a request's IP address to the request's context.
 // If getwtxt is behind a reverse proxy, get the last entry
-// in the X-Forwarded-For HTTP header as the user IP.
+// in the X-Forwarded-For or X-Real-IP HTTP header as the user IP.
 func newCtxUserIP(ctx context.Context, r *http.Request) context.Context {
 
 	base := strings.Split(r.RemoteAddr, ":")
@@ -22,6 +22,12 @@ func newCtxUserIP(ctx context.Context, r *http.Request) context.Context {
 		uip = base[0]
 	}
 
+	if _, ok := r.Header["X-Real-IP"]; ok {
+		proxied := r.Header["X-Real-IP"]
+		base = strings.Split(proxied[len(proxied)-1], ":")
+		uip = base[0]
+	}
+
 	return context.WithValue(ctx, ctxKey, uip)
 }
 
> 109 110 111 112 113 114