Skip to content

Instantly share code, notes, and snippets.

@hiteshchopra11
Created January 16, 2022 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiteshchopra11/a59038acd07c8e6329c1ee5ebe223246 to your computer and use it in GitHub Desktop.
Save hiteshchopra11/a59038acd07c8e6329c1ee5ebe223246 to your computer and use it in GitHub Desktop.
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