Skip to content

Commit

Permalink
update to use X-Forwarded-For
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 7, 2017
1 parent 3eb8641 commit 7e44d63
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}

0 comments on commit 7e44d63

Please # to comment.