Olivier Patry
10/11/2024, 4:55 PMHttpClient
so that I can inject the root URL from DI and just consume HttpClient
elsewhere without knowing about it, using only "path" in requests.
When using a prod URL it works, when using localhost:8080 it fails.
If I remove this mechanism and inline <http://localhost:8080>
before all "path" it works too.
So, I can't figure out where the issue resides 😞
🧵Olivier Patry
10/11/2024, 4:56 PMdefaultRequest {
if (url.host.isEmpty()) {
val defaultUrl = URLBuilder().takeFrom("<http://localhost:8080>")
url.host = defaultUrl.host
url.port = defaultUrl.port
url.protocol = defaultUrl.protocol
if (!url.encodedPath.startsWith('/')) {
val basePath = defaultUrl.encodedPath
url.encodedPath = "$basePath/${url.encodedPath}"
}
}
}
Olivier Patry
10/11/2024, 4:56 PMhttpClient.post("some/endpoint")
❌
httpClient.post("/some/endpoint")
❌
vs
httpClient.post("<http://localhost:8080/some/endpoint>")
✅Olivier Patry
10/11/2024, 4:58 PMConnectException
java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:50)
at io.ktor.network.sockets.SocketImpl$connect$1.invokeSuspend(SocketImpl.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:823)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)
Olivier Patry
10/11/2024, 5:23 PMlocalhost
in default requestChrimaeon
10/11/2024, 6:31 PMOlivier Patry
10/12/2024, 6:08 AMAleksei Tirman [JB]
10/14/2024, 9:11 AMOlivier Patry
10/14/2024, 9:39 AM