···214 var h http.Handler
215 h = mux
216 h = internal.DefaultXRealIP(*debugXRealIPDefault, h)
0217218 srv := http.Server{Handler: h}
219 listener, url := setupListener(*bindNetwork, *bind)
···214 var h http.Handler
215 h = mux
216 h = internal.DefaultXRealIP(*debugXRealIPDefault, h)
217+ h = internal.XForwardedForToXRealIP(h)
218219 srv := http.Server{Handler: h}
220 listener, url := setupListener(*bindNetwork, *bind)
+7
docs/docs/CHANGELOG.md
···1112## [Unreleased]
13000000014## v1.14.0
1516Livia sas Junius
···1112## [Unreleased]
1314+## v1.14.1
15+16+Livia sas Junius: Echo 1
17+18+- Set the `X-Real-Ip` header based on the contents of `X-Forwarded-For`
19+ [#62](https://github.com/TecharoHQ/anubis/issues/62)
20+21## v1.14.0
2223Livia sas Junius
···5 "net/http"
67 "github.com/TecharoHQ/anubis"
08)
910// UnchangingCache sets the Cache-Control header to cache a response for 1 year if
···33 next.ServeHTTP(w, r)
34 })
35}
00000000000000
···5 "net/http"
67 "github.com/TecharoHQ/anubis"
8+ "github.com/sebest/xff"
9)
1011// UnchangingCache sets the Cache-Control header to cache a response for 1 year if
···34 next.ServeHTTP(w, r)
35 })
36}
37+38+// XForwardedForToXRealIP sets the X-Real-Ip header based on the contents
39+// of the X-Forwarded-For header.
40+func XForwardedForToXRealIP(next http.Handler) http.Handler {
41+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
42+ if xffHeader := r.Header.Get("X-Forwarded-For"); r.Header.Get("X-Real-Ip") == "" && xffHeader != "" {
43+ ip := xff.Parse(xffHeader)
44+ slog.Debug("setting x-real-ip", "val", ip)
45+ r.Header.Set("X-Real-Ip", ip)
46+ }
47+48+ next.ServeHTTP(w, r)
49+ })
50+}