MCPcopy Index your code
hub / github.com/labstack/echo / ExtractIPFromRealIPHeader

Function ExtractIPFromRealIPHeader

ip.go:224–237  ·  view source on GitHub ↗

ExtractIPFromRealIPHeader extracts IP address using `x-real-ip` header. Use this if you put proxy which uses this header.

(options ...TrustOption)

Source from the content-addressed store, hash-verified

222// ExtractIPFromRealIPHeader extracts IP address using `x-real-ip` header.
223// Use this if you put proxy which uses this header.
224func ExtractIPFromRealIPHeader(options ...TrustOption) IPExtractor {
225 checker := newIPChecker(options)
226 return func(req *http.Request) string {
227 realIP := req.Header.Get(HeaderXRealIP)
228 if realIP != "" {
229 realIP = strings.TrimPrefix(realIP, "[")
230 realIP = strings.TrimSuffix(realIP, "]")
231 if ip := net.ParseIP(realIP); ip != nil && checker.trust(ip) {
232 return realIP
233 }
234 }
235 return extractIP(req)
236 }
237}
238
239// ExtractIPFromXFFHeader extracts IP address using `x-forwarded-for` header.
240// Use this if you put proxy which uses this header.

Callers 2

TestContext_RealIPFunction · 0.85

Calls 4

newIPCheckerFunction · 0.85
extractIPFunction · 0.85
trustMethod · 0.80
GetMethod · 0.45

Tested by 2

TestContext_RealIPFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…