summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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)
 }
 
2019-05-27 01:06:50 -0400 changed config format to yaml, commented config file' href='/gbmor/getwtxt/commit/getwtxt.yml?h=v0.4.13&id=daa48539f5ad8b444637f948b98996d35852b1e8'>daa4853 ^
69217dd ^
daa4853 ^























c5cf0e1 ^

daa4853 ^

c5cf0e1 ^
daa4853 ^



c5cf0e1 ^
daa4853 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85