mirror of https://github.com/dirtbags/moth.git
Make X-Forwarded-For handling an optional flag
This commit is contained in:
parent
cf72f8f253
commit
d9277ad423
|
@ -340,11 +340,15 @@ func (ctx *Instance) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
|
||||||
statusCode: new(int),
|
statusCode: new(int),
|
||||||
}
|
}
|
||||||
|
|
||||||
clientIP := r.Header.Get("X-Forwarded-For")
|
clientIP := r.RemoteAddr
|
||||||
clientIP = strings.Split(clientIP, ", ")[0]
|
|
||||||
|
|
||||||
if clientIP == "" {
|
if (ctx.UseXForwarded) {
|
||||||
clientIP = r.RemoteAddr
|
forwardedIP := r.Header.Get("X-Forwarded-For")
|
||||||
|
forwardedIP = strings.Split(forwardedIP, ", ")[0]
|
||||||
|
|
||||||
|
if forwardedIP != "" {
|
||||||
|
clientIP = forwardedIP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.mux.ServeHTTP(w, r)
|
ctx.mux.ServeHTTP(w, r)
|
||||||
|
|
|
@ -25,6 +25,7 @@ type Instance struct {
|
||||||
StateDir string
|
StateDir string
|
||||||
ThemeDir string
|
ThemeDir string
|
||||||
AttemptInterval time.Duration
|
AttemptInterval time.Duration
|
||||||
|
UseXForwarded bool
|
||||||
|
|
||||||
Runtime RuntimeConfig
|
Runtime RuntimeConfig
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,12 @@ func main() {
|
||||||
20*time.Second,
|
20*time.Second,
|
||||||
"Time between maintenance tasks",
|
"Time between maintenance tasks",
|
||||||
)
|
)
|
||||||
|
flag.BoolVar(
|
||||||
|
&ctx.UseXForwarded,
|
||||||
|
"x-forwarded-for",
|
||||||
|
false,
|
||||||
|
"Emit IPs from the X-Forwarded-For header in logs, when available, instead of the source IP. Use this when running behind a load-balancer or proxy",
|
||||||
|
)
|
||||||
listen := flag.String(
|
listen := flag.String(
|
||||||
"listen",
|
"listen",
|
||||||
":8080",
|
":8080",
|
||||||
|
|
Loading…
Reference in New Issue