feat(botfilter): add parseRemoteAddress
This commit is contained in:
1 parent
fcfe9ee976
commit
9bbc554ecf
1 file changed
+12
@@ -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()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user