Hi all. I'm trying to get a ktor client talking to...
# ktor
x
Hi all. I'm trying to get a ktor client talking to a REST service that is served via a wifi infrastructure access point on Android. Is there a way to configure an
HttpClient(Android)
with a custom
URLConnection
?
Copy code
val urlConnection: URLConnection = network.openConnection(URL(connection.serverUri))
urlConnection.connect()

val client = HttpClient(Android){
 // configure the client to use the url connection from the network
}
a
You can configure the
HttpURLConnection
created by Ktor using the requestConfig configuration method.
x
Thanks @Aleksei Tirman [JB]. Bit confused about this signature
Copy code
public class AndroidEngineConfig : HttpClientEngineConfig() {
    /**
     * Allows you to configure [HTTPS](<https://ktor.io/docs/client-ssl.html>) settings for this engine.
     */
    public var sslManager: (HttpsURLConnection) -> Unit = {}

    /**
     * Allows you to set engine-specific request configuration.
     */
    public var requestConfig: HttpURLConnection.() -> Unit = {}
}
Are we just supposed to do this?
Copy code
HttpClient(Android) {
  engine {
    requestConfig(urlConnection)
    sslManager(urlConnection)
  }
}