Documentation
¶
Index ¶
- func GetHostAndPortFromRemoteAddr(remoteAddr string) (string, int)
- func GetHostAndPortFromRequest(req *http.Request) (string, int)
- func GetRemoteAddrFromRequest(req *http.Request) string
- func IPInAny(host string, nets []*net.IPNet) bool
- func IsPrivateOrLoopback(host string) bool
- func ParseCIDRs(spec string) ([]*net.IPNet, error)
- func RequestIPChain(req *http.Request) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHostAndPortFromRemoteAddr ¶ added in v0.0.19
func GetHostAndPortFromRequest ¶ added in v0.0.19
func GetRemoteAddrFromRequest ¶ added in v0.0.19
func IPInAny ¶ added in v0.1.2
IPInAny reports whether host (a bare IP, no port) falls within any of the given networks. A non-IP host or an empty network list returns false.
func IsPrivateOrLoopback ¶ added in v0.0.24
IsPrivateOrLoopback reports whether host is a loopback, RFC1918 private, or link-local IP address. host should be a bare IP (no port); non-IP hostnames return false. Used to exempt trusted/local sources (operators testing, internal SSRF callbacks) from volume-based bot detection.
func ParseCIDRs ¶ added in v0.1.2
ParseCIDRs parses a comma-separated list of CIDRs and bare IPs into networks. A bare IP (e.g. "1.2.3.4" or "2001:db8::1") is treated as a single-host network (/32 or /128). Empty entries and surrounding whitespace are ignored; an empty spec yields a nil slice and no error. The first unparseable entry returns an error so config mistakes surface loudly rather than silently matching nothing.
func RequestIPChain ¶ added in v0.0.24
RequestIPChain returns the unique, order-preserving chain of source IPs for an HTTP request: X-Forwarded-For entries (client first), then X-Real-Ip, then the direct TCP peer. Duplicates are collapsed. Forwarded headers are client-controlled and can be spoofed, so treat the chain as informational rather than authoritative.
Types ¶
This section is empty.