MCPcopy Index your code
hub / github.com/dreamsofcode-io/zenstats / getIP

Function getIP

internal/handler/index.go:61–71  ·  view source on GitHub ↗

TODO - Test this

(r *http.Request, steps int)

Source from the content-addressed store, hash-verified

59
60// TODO - Test this
61func 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
73func (h *Index) ServeHTTP(w http.ResponseWriter, r *http.Request) {
74 ip := getIP(r, 0)

Callers 1

ServeHTTPMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected