Created
January 16, 2022 22:44
-
-
Save hiteshchopra11/a59038acd07c8e6329c1ee5ebe223246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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