TODO - Test this
(r *http.Request, steps int)
| 59 | |
| 60 | // TODO - Test this |
| 61 | func getIP(r *http.Request, steps int) string { |
| 62 | xff := r.Header.Get("X-Forwarded-For") |
| 63 | xffParts := re.Split(xff, -1) |
| 64 | |
| 65 | if xff == "" || len(xffParts) <= steps { |
| 66 | remoteParts := strings.Split(r.RemoteAddr, ":") |
| 67 | return strings.Join(remoteParts[:len(remoteParts)-1], ":") |
| 68 | } |
| 69 | |
| 70 | return xffParts[len(xffParts)-(steps+1)] |
| 71 | } |
| 72 | |
| 73 | func (h *Index) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 74 | ip := getIP(r, 0) |