MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / trustMulti

Function trustMulti

packages/proxy-addr/src/index.ts:149–172  ·  view source on GitHub ↗

* Compile trust function for multiple subnets.

(subnets: any[])

Source from the content-addressed store, hash-verified

147 * Compile trust function for multiple subnets.
148 */
149function trustMulti(subnets: any[]) {
150 return function trust(addr: string) {
151 if (!isip(addr)) return false
152 const ip = parseip(addr)
153 let ipconv
154 const kind = ip.kind()
155 for (let i = 0; i < subnets.length; i++) {
156 const subnet = subnets[i]
157 const subnetip = subnet[0]
158 const subnetkind = subnetip.kind()
159 const subnetrange = subnet[1]
160 let trusted = ip
161 if (kind !== subnetkind) {
162 if (subnetkind === 'ipv4' && !(ip as IPv6).isIPv4MappedAddress()) continue
163
164 if (!ipconv) ipconv = subnetkind === 'ipv4' ? (ip as IPv6).toIPv4Address() : (ip as IPv4).toIPv4MappedAddress()
165
166 trusted = ipconv
167 }
168 if ((trusted as IPv4).match(subnetip, subnetrange)) return true
169 }
170 return false
171 }
172}
173/**
174 * Compile trust function for single subnet.
175 *

Callers 1

compileTrustFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected