MCPcopy
hub / github.com/PatchMon/PatchMon / isLoopback

Function isLoopback

server-source-code/internal/middleware/cors.go:194–208  ·  view source on GitHub ↗

isLoopback returns true if the host (with or without port) is a loopback address. This allows internal health checks and agent connections that bypass the proxy.

(hostPort string)

Source from the content-addressed store, hash-verified

192// isLoopback returns true if the host (with or without port) is a loopback address.
193// This allows internal health checks and agent connections that bypass the proxy.
194func isLoopback(hostPort string) bool {
195 host := hostPort
196 if idx := strings.LastIndex(hostPort, ":"); idx != -1 {
197 // Handle IPv6 [::1]:port
198 if strings.Contains(hostPort, "]") {
199 host = strings.TrimPrefix(hostPort[:strings.Index(hostPort, "]")+1], "[")
200 host = strings.TrimSuffix(host, "]")
201 } else {
202 host = hostPort[:idx]
203 }
204 }
205 host = strings.TrimPrefix(host, "[")
206 host = strings.TrimSuffix(host, "]")
207 return host == "localhost" || host == "127.0.0.1" || host == "::1" || strings.HasPrefix(host, "127.")
208}

Callers 1

CORSFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected