MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / ClientIP

Function ClientIP

pkg/utils/ip.go:9–26  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

7)
8
9func ClientIP(r *http.Request) string {
10 xForwardedFor := r.Header.Get("X-Forwarded-For")
11 ip := strings.TrimSpace(strings.Split(xForwardedFor, ",")[0])
12 if ip != "" {
13 return ip
14 }
15
16 ip = strings.TrimSpace(r.Header.Get("X-Real-Ip"))
17 if ip != "" {
18 return ip
19 }
20
21 if ip, _, err := net.SplitHostPort(strings.TrimSpace(r.RemoteAddr)); err == nil {
22 return ip
23 }
24
25 return ""
26}
27
28func IsLocalIPAddr(ip string) bool {
29 return IsLocalIP(net.ParseIP(ip))

Callers 2

handleGetHeadPostMethod · 0.92
directObjectURLFunction · 0.92

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected