MCPcopy
hub / github.com/gofiber/fiber / IP

Method IP

req.go:559–569  ·  req.go::DefaultReq.IP

IP returns the client's IP address. When the request comes from a trusted proxy (see [TrustProxyConfig]), the value is extracted from the configured ProxyHeader by walking the X-Forwarded-For chain right-to-left and skipping all trusted proxy IPs; the first non-trusted IP in the chain is returned. P

()

Source from the content-addressed store, hash-verified

557// non-trusted IP in the chain is returned. Please use Config.TrustProxy to prevent header
558// spoofing if your app is behind a proxy.
559func (r *DefaultReq) IP() string {
560 app := r.c.app
561 if r.IsProxyTrusted() && app.config.ProxyHeader != "" {
562 return r.extractIPFromHeader(app.config.ProxyHeader)
563 }
564
565 if ip := r.c.fasthttp.RemoteIP(); ip != nil {
566 return ip.String()
567 }
568 return ""
569}
570
571// extractIPsFromHeader will return a slice of IPs it found given a header name in the order they appear.
572// When IP validation is enabled, any invalid IPs will be omitted.

Callers

nothing calls this directly

Calls 3

IsProxyTrustedMethod · 0.95
extractIPFromHeaderMethod · 0.95
StringMethod · 0.65

Tested by

no test coverage detected