jvm.io.realm.kotlin.mongodb.internal.HttpClientCache.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of library-sync Show documentation
Show all versions of library-sync Show documentation
Sync Library code for Realm Kotlin. This artifact is not supposed to be consumed directly, but through 'io.realm.kotlin:gradle-plugin:1.6.2' instead.
@file:JvmName("HttpClientCacheJVM")
package io.realm.kotlin.mongodb.internal
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.logging.Logger
/**
* Cache HttpClient on Android and JVM.
* https://github.com/realm/realm-kotlin/issues/480 only seem to be a problem on macOS.
*/
internal actual class HttpClientCache actual constructor(timeoutMs: Long, customLogger: Logger?) {
private val httpClient: HttpClient by lazy { createClient(timeoutMs, customLogger) }
actual fun getClient(): HttpClient {
return httpClient
}
actual fun close() {
httpClient.close()
}
}
public actual fun createPlatformClient(block: HttpClientConfig<*>.() -> Unit): HttpClient {
return HttpClient(OkHttp) {
engine {
config {
retryOnConnectionFailure(true)
}
}
this.apply(block)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy