summaryrefslogtreecommitdiff
path: root/srv/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'srv/src/http')
-rw-r--r--srv/src/http/middleware.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/srv/src/http/middleware.go b/srv/src/http/middleware.go
index 943bc05..b82fc29 100644
--- a/srv/src/http/middleware.go
+++ b/srv/src/http/middleware.go
@@ -40,15 +40,24 @@ func setLoggerMiddleware(logger *mlog.Logger) middleware {
type logCtxKey string
- ip, _, _ := net.SplitHostPort(r.RemoteAddr)
-
ctx := r.Context()
ctx = mctx.Annotate(ctx,
- logCtxKey("remote_ip"), ip,
logCtxKey("url"), r.URL,
logCtxKey("method"), r.Method,
)
+ if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
+ ctx = mctx.Annotate(ctx, logCtxKey("x_forwarded_for"), xff)
+ }
+
+ if xrip := r.Header.Get("X-Real-IP"); xrip != "" {
+ ctx = mctx.Annotate(ctx, logCtxKey("x_real_ip"), xrip)
+ }
+
+ if ip, _, _ := net.SplitHostPort(r.RemoteAddr); ip != "" {
+ ctx = mctx.Annotate(ctx, logCtxKey("remote_ip"), ip)
+ }
+
r = r.WithContext(ctx)
r = apiutil.SetRequestLogger(r, logger)
h.ServeHTTP(rw, r)