Skip to content

Commit

Permalink
Do not scan classpath on every HttpClient instantiation, provide bett…
Browse files Browse the repository at this point in the history
…er error message
  • Loading branch information
qwwdfsad authored and e5l committed Aug 22, 2018
1 parent 81f55a6 commit ce32922
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import java.util.*
actual fun HttpClient(
useDefaultTransformers: Boolean,
block: HttpClientConfig<*>.() -> Unit
): HttpClient = HttpClient(findAvailableFactory(), useDefaultTransformers, block)
): HttpClient = HttpClient(FACTORY, useDefaultTransformers, block)

interface HttpClientEngineContainer {
val factory: HttpClientEngineFactory<*>
}

internal fun findAvailableFactory(): HttpClientEngineFactory<*> =
ServiceLoader.load(HttpClientEngineContainer::class.java).toList().first().factory
private val FACTORY = ServiceLoader.load(HttpClientEngineContainer::class.java)
.toList()
.firstOrNull()
?.factory ?: error("Failed to find HttpClientEngineContainer in classpath via ServiceLoader")

0 comments on commit ce32922

Please sign in to comment.