ServerUrls.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/http/ServerUrls.kt
1package eu.friedcutlet.yokan.services.http23/** yokan-hub base URL: `https://` unless a scheme is given; no trailing slash. `null` when blank. */4fun normalizeHubServer(server: String?): String? {5 val s = server?.trim()?.trimEnd('/') ?: return null6 if (s.isBlank()) return null7 return if ("://" in s) s else "https://$s"8}910/** WebSocket base for a normalized hub URL: `https` → `wss`, `http` → `ws`. */11fun hubWebSocketBase(server: String): String = when {12 server.startsWith("https://") -> "wss://" + server.removePrefix("https://")13 server.startsWith("http://") -> "ws://" + server.removePrefix("http://")14 else -> server15}1617/** Whether [url] points at this device (the embedded extension server/proxy case). */18internal fun isLoopbackProxy(url: String): Boolean =19 url.contains("://127.0.0.1") ||20 url.contains("://localhost") ||21 url.contains("://[::1]")22