From cb95df096d3d7bcfcb1f6c6a07ed3f985f912b2a Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 17 Oct 2018 16:30:34 +0200 Subject: [PATCH] Handle X-Forwarded-For header in log --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index 77633b9..3796ce8 100644 --- a/main.go +++ b/main.go @@ -105,6 +105,9 @@ func genStudents() map[string]map[string]*Submission { } func ServeJSON(w http.ResponseWriter, r *http.Request) { + if addr := r.Header.Get("X-Forwarded-For"); addr != "" { + r.RemoteAddr = addr + } log.Printf("Handling %s request from %s: %s [%s]\n", r.Method, r.RemoteAddr, r.URL.Path, r.UserAgent()) w.Header().Set("Content-Type", "application/json") @@ -146,6 +149,9 @@ func genStudent(login string) map[string]*Submission { } func ServeJSONStudent(w http.ResponseWriter, r *http.Request) { + if addr := r.Header.Get("X-Forwarded-For"); addr != "" { + r.RemoteAddr = addr + } log.Printf("Handling %s request from %s: %s [%s]\n", r.Method, r.RemoteAddr, r.URL.Path, r.UserAgent()) w.Header().Set("Content-Type", "application/json")