MCPcopy Create free account
hub / github.com/ericls/imgdd / ExtractIPXFF

Function ExtractIPXFF

httpserver/ip.go:14–29  ·  view source on GitHub ↗
(req *http.Request)

Source from the content-addressed store, hash-verified

12}
13
14func ExtractIPXFF(req *http.Request) string {
15 xffIps := req.Header["X-Forwarded-For"]
16 if len(xffIps) == 0 {
17 return ""
18 }
19 ips := strings.Split(strings.Join(xffIps, ","), ",")
20 for i := len(ips) - 1; i >= 0; i-- {
21 ips[i] = strings.TrimSpace(ips[i])
22 ips[i] = strings.TrimPrefix(ips[i], "[")
23 ips[i] = strings.TrimSuffix(ips[i], "]")
24 if net.ParseIP(ips[i]) == nil {
25 return ""
26 }
27 }
28 return strings.TrimSpace(ips[0])
29}
30
31func ExtractIP(req *http.Request) string {
32 ip := ExtractIPXFF(req)

Callers 1

ExtractIPFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected