Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class HttpClient(
public val engine: HttpClientEngine,
private val userConfig: HttpClientConfig<out HttpClientEngineConfig> = HttpClientConfig()
) : {
init {
with(userConfig) {
config.install(HttpRequestLifecycle)
config.install(BodyProgress)
if (useDefaultTransformers) {
config.install(HttpPlainText)
config.install("DefaultTransformers") { defaultTransformers() }
}
config.install(HttpSend)
if (followRedirects) {
config.install(HttpRedirect)
}
config += this
config.addDefaultResponseValidation()
config.install(this@HttpClient)
}
}
/**
* Returns a new [HttpClient] copying this client configuration,
* and additionally configured by the [block] parameter.
*/
public fun config(block: HttpClientConfig<*>.() -> Unit): HttpClient = HttpClient(
engine,
HttpClientConfig<HttpClientEngineConfig>().apply {
plusAssign(userConfig)
block()
},
manageEngine
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment