MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / realIP

Function realIP

internal/serverapi/sub.go:99–114  ·  view source on GitHub ↗

realIP 从请求中提取客户端真实 IP(优先读 X-Real-IP / X-Forwarded-For)。

(r *http.Request)

Source from the content-addressed store, hash-verified

97
98// realIP 从请求中提取客户端真实 IP(优先读 X-Real-IP / X-Forwarded-For)。
99func realIP(r *http.Request) string {
100 if ip := r.Header.Get("X-Real-IP"); ip != "" {
101 return ip
102 }
103 if fwd := r.Header.Get("X-Forwarded-For"); fwd != "" {
104 if idx := strings.IndexByte(fwd, ','); idx >= 0 {
105 fwd = fwd[:idx]
106 }
107 return strings.TrimSpace(fwd)
108 }
109 host, _, err := net.SplitHostPort(r.RemoteAddr)
110 if err != nil {
111 return r.RemoteAddr
112 }
113 return host
114}
115
116// buildUserinfo 生成 Subscription-Userinfo header 值。
117func buildUserinfo(u users.User) string {

Callers 1

handleSubMethod · 0.85

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected