🔄 Upstream Parity: Fix gateway setup URL port parsing (#401)

Fixes default port logic in parseGatewayEndpoint: WSS/HTTPS bare URLs default to 443, WS/HTTP default to 18789. Display URL omits port when it matches protocol default.
This commit is contained in:
Yu-ga
2026-04-05 21:41:46 +09:00
committed by GitHub
parent 8a1abb7872
commit dcd74fbe09
4 changed files with 70 additions and 4 deletions
@@ -38,8 +38,22 @@ object GatewayConfigUtils {
"wss", "https" -> true
else -> true
}
val port = uri.port.takeIf { it in 1..65535 } ?: if (tls) 443 else 18789
val displayUrl = "${if (tls) "https" else "http"}://$host:$port"
val defaultPort = when (scheme) {
"wss", "https" -> 443
"ws", "http" -> 18789
else -> 443
}
val displayPort = when (scheme) {
"wss", "https" -> 443
"ws", "http" -> 80
else -> 443
}
val port = uri.port.takeIf { it in 1..65535 } ?: defaultPort
val displayUrl = if (port == displayPort && defaultPort == displayPort) {
"${if (tls) "https" else "http"}://$host"
} else {
"${if (tls) "https" else "http"}://$host:$port"
}
if (!tls && !NetworkUtils.isUrlSecure(displayUrl)) {
return null
@@ -111,5 +111,42 @@ class GatewayConfigUtilsTest {
assertNotNull(result)
assertEquals(443, result!!.port)
assertEquals(true, result.tls)
assertEquals("https://example.com", result.displayUrl)
}
@Test
fun `parseGatewayEndpoint UsesDefaultCleartextPortForBareWsUrls`() {
val result = GatewayConfigUtils.parseGatewayEndpoint("ws://192.168.1.100")
assertNotNull(result)
assertEquals(18789, result!!.port)
assertEquals(false, result.tls)
assertEquals("http://192.168.1.100:18789", result.displayUrl)
}
@Test
fun `parseGatewayEndpoint OmitsExplicitDefaultTlsPortFromDisplayUrl`() {
val result = GatewayConfigUtils.parseGatewayEndpoint("https://example.com:443")
assertNotNull(result)
assertEquals(443, result!!.port)
assertEquals(true, result.tls)
assertEquals("https://example.com", result.displayUrl)
}
@Test
fun `parseGatewayEndpoint KeepsExplicitNonDefaultPortInDisplayUrl`() {
val result = GatewayConfigUtils.parseGatewayEndpoint("http://192.168.1.100:8080")
assertNotNull(result)
assertEquals(8080, result!!.port)
assertEquals(false, result.tls)
assertEquals("http://192.168.1.100:8080", result.displayUrl)
}
@Test
fun `parseGatewayEndpoint KeepsExplicitCleartextPort80InDisplayUrl`() {
val result = GatewayConfigUtils.parseGatewayEndpoint("http://192.168.1.100:80")
assertNotNull(result)
assertEquals(80, result!!.port)
assertEquals(false, result.tls)
assertEquals("http://192.168.1.100:80", result.displayUrl)
}
}
+15
View File
@@ -0,0 +1,15 @@
**Source**
Upstream openclaw/openclaw commit `8790c54635`
**Why**
Gateway setup URLs or explicit manual endpoint inputs shouldn't enforce default ports blindly when displaying the connection UI or verifying connection security, particularly ensuring custom or cleartext implicit ports accurately reflect their configuration.
**Adaptation**
Ported the modified `displayUrl` string building logic from `GatewayConfigResolver.kt` (upstream) to `GatewayConfigUtils.kt` (this repo). Added tests covering various edge cases (bare domains vs default ports).
Modified test parameters in `GatewayConfigUtilsTest` to use local `192.168.1.100` instead of `gateway.example` for cleartext, as `NetworkUtils.isUrlSecure` in this repo explicitly forbids public domains for WS/HTTP connections.
**Excluded upstream behavior**
N/A. This was a direct logic porting.
**Verification**
Locally verified by running `./gradlew app:testStandardDebugUnitTest app:lintStandardDebug` ensuring all updated assertions succeed and no memory or regressions are flagged.
+2 -2
View File
@@ -1,7 +1,7 @@
pluginManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://repo1.maven.org/maven2/") }
gradlePluginPortal()
}
}
@@ -9,7 +9,7 @@ dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://repo1.maven.org/maven2/") }
maven { url = uri("https://jitpack.io") }
}
}