https://kotlinlang.org logo
#ktor
Title
# ktor
h

Hasan Hosgel (alosdev)

03/24/2021, 8:45 AM
hi all, I’m facing a small problem with the ktor client proxy configuration. my current setup is, that I’m using the apache engine in my ktor client, as I need a connection with credentials. But I have also a different problem. how I can also route connection differently for some hosts? So host1 should use the proxy settings and host2 don’t. I hope I can get some guidance here.
r

Ronald van D

03/24/2021, 2:24 PM
I’m not sure if I understand it correctly. But you could create two HttpClients and inject the ones you need. For example with Koin you could do something like this:
Copy code
val networkModule = module {
    factory(named("custom"))  { customEngineHttpClient() }
    factory(named("normal"))  { defaultEngineHttpClient() }
    //... other networking stuff
}

private fun customEngineHttpClient() =
    HttpClient {
        install(HttpCallValidator)
        install(JsonFeature) {
          //... KotlinXSerializer
        }
    }

private fun defaultEngineHttpClient() =
    HttpClient {
        install(HttpCallValidator)
        install(JsonFeature) {
          //... KotlinXSerializer
        }
    }
h

Hasan Hosgel (alosdev)

03/24/2021, 3:37 PM
yes I could do that but hoped, I can do it without two clients :)
30 Views