diff --git a/util.go b/util.go index 81477174..2fd412d8 100644 --- a/util.go +++ b/util.go @@ -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() +} +