(host)
| 43 | |
| 44 | /** 127.0.0.0/8, ::1 und ihre Schreibweisen. Nur diese gelten als lokal. */ |
| 45 | export function isLoopbackHost(host) { |
| 46 | if (host === undefined || host === null) { return false; } |
| 47 | let h = host.trim(); |
| 48 | if (h.startsWith('[') && h.endsWith(']')) { h = h.slice(1, -1); } |
| 49 | if (h === 'localhost' || h === '::1' || h === '0:0:0:0:0:0:0:1') { return true; } |
| 50 | const v4 = h.startsWith('::ffff:') ? h.slice(7) : h; |
| 51 | return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v4); |
| 52 | } |
| 53 | |
| 54 | /** Trennt "127.0.0.1:52000" oder "[::1]:52000" in Host und Port. */ |
| 55 | export function splitHostPort(endpoint) { |
no outgoing calls
no test coverage detected