MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / GetClientString

Function GetClientString

pkg/ip/realclientip.go:94–114  ·  view source on GitHub ↗

GetClientString obtains the human readable string of the remote IP and optionally the real client IP if available

(p ipapi.RealClientIPParser, req *http.Request, full bool)

Source from the content-addressed store, hash-verified

92
93// GetClientString obtains the human readable string of the remote IP and optionally the real client IP if available
94func GetClientString(p ipapi.RealClientIPParser, req *http.Request, full bool) (s string) {
95 var realClientIPStr string
96 if p != nil {
97 if realClientIP, err := p.GetRealClientIP(req.Header); err == nil && realClientIP != nil {
98 realClientIPStr = realClientIP.String()
99 }
100 }
101
102 var remoteIPStr string
103 if remoteIP, err := getRemoteIP(req); err == nil && remoteIP != nil {
104 remoteIPStr = remoteIP.String()
105 }
106
107 if !full && realClientIPStr != "" {
108 return realClientIPStr
109 }
110 if full && realClientIPStr != "" {
111 return fmt.Sprintf("%s (%s)", remoteIPStr, realClientIPStr)
112 }
113 return remoteIPStr
114}

Callers 3

OAuthCallbackMethod · 0.92
ValidateFunction · 0.92
TestGetClientStringFunction · 0.85

Calls 3

getRemoteIPFunction · 0.85
GetRealClientIPMethod · 0.65
StringMethod · 0.45

Tested by 1

TestGetClientStringFunction · 0.68