mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-07 04:38:19 +08:00
refactor(engine): streamline CIDR preparation for trusted proxies
This commit is contained in:
parent
334dbdb8ac
commit
16857146c8
10
gin.go
10
gin.go
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user