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
()
| 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. |
| 559 | func (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. |
nothing calls this directly
no test coverage detected