5824: Log X-Forwarded-For header value if provided.
authorTom Clegg <tom@curoverse.com>
Fri, 28 Aug 2015 06:30:45 +0000 (02:30 -0400)
committerTom Clegg <tom@curoverse.com>
Sat, 17 Oct 2015 00:02:16 +0000 (20:02 -0400)
services/keep-web/handler.go

index 98dfdb31dd3650f610df1fcf06dd698fc49f87ab..600e68506df3665bdfb7a4736c67d1e3841afd14 100644 (file)
@@ -62,6 +62,11 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
        var statusCode = 0
        var statusText string
 
+       remoteAddr := r.RemoteAddr
+       if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
+               remoteAddr = xff + "," + remoteAddr
+       }
+
        w := httpserver.WrapResponseWriter(wOrig)
        defer func() {
                if statusCode == 0 {
@@ -75,7 +80,7 @@ func (h *handler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
                if statusText == "" {
                        statusText = http.StatusText(statusCode)
                }
-               httpserver.Log(r.RemoteAddr, statusCode, statusText, w.WroteBodyBytes(), r.Method, r.Host, r.URL.Path, r.URL.RawQuery)
+               httpserver.Log(remoteAddr, statusCode, statusText, w.WroteBodyBytes(), r.Method, r.Host, r.URL.Path, r.URL.RawQuery)
        }()
 
        if r.Method != "GET" && r.Method != "POST" {