summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-25 03:38:36 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-25 03:38:36 -0400
commit07872ef4cafab8b7c975936057c779799bb655ff (patch)
treeb9f7306b1703b7be2b0b48c679b857b7b55bc0d0
parent55c8ffa2d8ef4509fd0f8b2035ec9c4af7e41b77 (diff)
downloadgetwtxt-07872ef4cafab8b7c975936057c779799bb655ff.tar.gz
checking for X-Real-IP header sometimes used by nginx when forwarding requests to getwtxt
-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)
 }
 
2bf0235be9e57e0e08b6328acc88add8b'>a978bb12 ^
a28f0d9e ^
a978bb12 ^











7f98e013 ^
d54cbf12 ^


d40998c4 ^








7f98e013 ^
d40998c4 ^
7f98e013 ^
d40998c4 ^



7f98e013 ^

d40998c4 ^


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
86
87