MCPcopy
hub / github.com/gin-gonic/gin / isTrustedProxy

Method isTrustedProxy

gin.go:469–479  ·  view source on GitHub ↗

isTrustedProxy will check whether the IP address is included in the trusted list according to Engine.trustedCIDRs

(ip net.IP)

Source from the content-addressed store, hash-verified

467
468// isTrustedProxy will check whether the IP address is included in the trusted list according to Engine.trustedCIDRs
469func (engine *Engine) isTrustedProxy(ip net.IP) bool {
470 if engine.trustedCIDRs == nil {
471 return false
472 }
473 for _, cidr := range engine.trustedCIDRs {
474 if cidr.Contains(ip) {
475 return true
476 }
477 }
478 return false
479}
480
481// validateHeader will parse X-Forwarded-For header and return the trusted client IP address
482func (engine *Engine) validateHeader(header string) (clientIP string, valid bool) {

Callers 4

validateHeaderMethod · 0.95
TestRemoteIPFailFunction · 0.80
ClientIPMethod · 0.80

Calls

no outgoing calls

Tested by 1

TestRemoteIPFailFunction · 0.64