feat(botfilter): add parseRemoteAddress

This commit is contained in:
hoelee committed 2026-01-13 14:33:00 +08:00
1 parent fcfe9ee976
commit 9bbc554ecf
1 file changed
+12
+12
View File
@@ -26,3 +26,15 @@ func clientIP(r *http.Request, cfg *compiledConfig) netip.Addr {
return remote
}
func parseRemoteAddress(value string) netip.Addr {
host, _, err := net.SplitHostPort(strings.TrimSpace(value))
if err == nil {
value = host
}
addr, err := netip.ParseAddr(strings.Trim(strings.TrimSpace(value), "[]"))
if err != nil {
return netip.Addr{}
}
return addr.Unmap()
}