```HttpClient(OkHttp) { engine { preco...
# ktor
u
Copy code
HttpClient(OkHttp) {
    engine {
        preconfigured = okHttpClient
    }
    install(DefaultRequest) {
        url("<http://10.0.2.2:8081/>")
    }
    install(ContentNegotiation) {
        json(json)
    }
    install(WebSockets)
}

val webSocketSession = ktorClient.webSocketSession("ws")
webSocketSession
doesnt seem to pickup the
DefaultRequest
base url If I duplicate the url again like this
Copy code
val wsUrl = URLBuilder("<http://10.0.2.2:8081/>")
    .apply {
        protocol = URLProtocol.WS
        path("ws")
    }
    .buildString()
val webSocketSession = ktorClient.webSocketSession(wsUrl)
then it works Is that normal? Am I using it wrong?
o
Don't know if it' the best, but I use this on my side
Copy code
defaultRequest {
                if (url.host.isEmpty()) {
                    val defaultUrl = URLBuilder().takeFrom("<http://10.0.2.2:8081>")
                    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}"
                    }
                }
            }
u
i mean, sure that fixes it, but sounds like it is an issue id expect default request to do all this
a
This is a bug.
👍 1