MCPcopy
hub / github.com/gofiber/fiber / handleTrustedProxy

Method handleTrustedProxy

app.go:824–840  ·  view source on GitHub ↗

Adds an ip address to TrustProxyConfig.ranges or TrustProxyConfig.ips based on whether it is an IP range or not

(ipAddress string)

Source from the content-addressed store, hash-verified

822
823// Adds an ip address to TrustProxyConfig.ranges or TrustProxyConfig.ips based on whether it is an IP range or not
824func (app *App) handleTrustedProxy(ipAddress string) {
825 if strings.IndexByte(ipAddress, '/') >= 0 {
826 _, ipNet, err := net.ParseCIDR(ipAddress)
827 if err != nil {
828 log.Warnf("IP range %q could not be parsed: %v", ipAddress, err)
829 } else {
830 app.config.TrustProxyConfig.ranges = append(app.config.TrustProxyConfig.ranges, ipNet)
831 }
832 } else {
833 ip := net.ParseIP(ipAddress)
834 if ip == nil {
835 log.Warnf("IP address %q could not be parsed", ipAddress)
836 } else {
837 app.config.TrustProxyConfig.ips[ipAddress] = struct{}{}
838 }
839 }
840}
841
842// setCtxFunc applies the given context factory to the app.
843// It is used internally by NewWithCustomCtx. It doesn't allow adding new methods,

Callers 1

NewFunction · 0.95

Calls 1

WarnfFunction · 0.92

Tested by

no test coverage detected