refactor(engine): streamline CIDR preparation for trusted proxies

This commit is contained in:
Shirshendu Bhowmick 2026-05-09 13:45:38 +05:30
parent 334dbdb8ac
commit 16857146c8
No known key found for this signature in database

10
gin.go
View File

@ -418,11 +418,13 @@ func (engine *Engine) prepareTrustedCIDRs() ([]netip.Prefix, error) {
if err != nil {
return cidrs, &net.ParseError{Type: "IP address", Text: trustedProxy}
}
if addr.Unmap().Is4() {
trustedProxy += "/32"
} else {
trustedProxy += "/128"
addr = addr.Unmap()
bits := 128
if addr.Is4() {
bits = 32
}
cidrs = append(cidrs, netip.PrefixFrom(addr, bits))
continue
}
prefix, err := netip.ParsePrefix(trustedProxy)
if err != nil {