From 7e44d63e033f66df5ae24c46d1a58f19c840fc9b Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Thu, 6 Jul 2017 20:20:55 -0700 Subject: [PATCH] update to use X-Forwarded-For --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 931d98f..4903c53 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ func main() { // addPoll creates a poll, responds with .id. func addPoll(w http.ResponseWriter, r *http.Request) { - user := r.Header.Get("X-Real-IP") + user := getUser(r) var body struct { Options []string `json:"options"` @@ -56,7 +56,7 @@ func addPoll(w http.ResponseWriter, r *http.Request) { func getPollOptionVote(w http.ResponseWriter, r *http.Request) { id := r.URL.Query().Get(":id") option := r.URL.Query().Get(":option") - user := r.Header.Get("X-Real-IP") + user := getUser(r) ctx := log.WithFields(log.Fields{ "id": id, @@ -150,3 +150,7 @@ func setETag(w http.ResponseWriter, body []byte) { etag := hex.EncodeToString(hash.Sum(nil)) w.Header().Set("ETag", `w/"`+etag+`"`) } + +func getUser(r *http.Request) string { + return r.Header.Get("X-Forwarded-For") +}