HttpClientConfig

A mutable HttpClient configuration used to adjust settings, install plugins and interceptors.

This configuration can be provided as a lambda in the HttpClient constructor or the HttpClient.config builder:

val client = HttpClient { // HttpClientConfig<Engine>()
// Configure engine settings
engine { // HttpClientEngineConfig
threadsCount = 4
pipelining = true
}

// Install and configure plugins
install(ContentNegotiation) {
json()
}

// Configure default request parameters
defaultRequest {
url("https://api.example.com")
header("X-Custom-Header", "value")
}

// Configure client-wide settings
expectSuccess = true
followRedirects = true
}

Configuring HttpClientEngine

If the engine is specified explicitly, engine-specific properties will be available in the engine block:

val client = HttpClient(CIO) { // HttpClientConfig<CIOEngineConfig>.() -> Unit
engine { // CIOEngineConfig.() -> Unit
// engine specific properties
}
}

Learn more about the client's configuration from Creating and configuring a client.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Development mode is no longer required all functionality is enabled by default. The property is safe to remove.

Link copied to clipboard

Terminates HttpClient.receivePipeline if the status code is not successful (>=300). Learn more from Response validation.

Link copied to clipboard

Specifies whether the client redirects to URLs provided in the Location header. You can disable redirections by setting this property to false.

Link copied to clipboard

Enables body transformations for many common types like String, ByteArray, ByteReadChannel, etc. These transformations are applied to the request and response bodies.

Functions

Link copied to clipboard

Default response validation. Check the response status code in range (0..299).

Link copied to clipboard

Installs the UserAgent plugin with a browser-like user agent.

Link copied to clipboard

Configure client charsets.

Link copied to clipboard

Clones this HttpClientConfig by duplicating all the plugins and customInterceptors.

Link copied to clipboard

Installs the UserAgent plugin with a CURL user agent.

Link copied to clipboard

Set default request parameters. See DefaultRequest

Link copied to clipboard
fun engine(block: T.() -> Unit)

A builder for configuring engine-specific settings in HttpClientEngineConfig, such as dispatcher, thread count, proxy, and more.

Link copied to clipboard
Link copied to clipboard
fun install(client: HttpClient)

Applies all the installed plugins and customInterceptors from this configuration into the specified client.

fun <TBuilder : Any, TPlugin : Any> install(plugin: HttpClientPlugin<TBuilder, TPlugin>, configure: TBuilder.() -> Unit = {})

Installs the specified plugin and optionally configures it using the configure block.

fun install(key: String, block: HttpClient.() -> Unit)

Installs an interceptor defined by block. The key parameter is used as a unique name, that also prevents installing duplicated interceptors.

Link copied to clipboard
operator fun plusAssign(other: HttpClientConfig<out T>)

Installs the plugin from the other client's configuration.

Link copied to clipboard

Install ResponseObserver plugin in client.

Link copied to clipboard
fun HttpClientConfig<*>.SSE(config: SSEConfig.() -> Unit)

Installs the SSE plugin using the config as configuration.

Link copied to clipboard

Installs the WebSockets plugin using the config as configuration.