Skip to content

Commit

Permalink
KTOR-6501 Add client KDocs for config and ObservableContent
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Nov 11, 2024
1 parent c71622a commit 2648fe3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,48 @@ package io.ktor.client
import io.ktor.client.engine.*
import io.ktor.client.plugins.*
import io.ktor.util.*
import io.ktor.util.collections.*
import io.ktor.utils.io.*
import kotlin.collections.set

/**
* A mutable [HttpClient] configuration.
* A mutable [HttpClient] configuration used to adjust settings, install plugins and interceptors.
*
* This class is available as block in [HttpClient] constructor or [HttpClient.config] builder:
* ```kotlin
* 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:
* ```kotlin
* 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](https://ktor.io/docs/create-client.html).
*/
Expand All @@ -25,7 +61,15 @@ public class HttpClientConfig<T : HttpClientEngineConfig> {
internal var engineConfig: T.() -> Unit = {}

/**
* Allows you to configure engine parameters.
* Builder for configuring engine-specific settings in [HttpClientEngineConfig]
* (like dispatcher, threads count, proxy, etc.)
*
* ```kotlin
* val client = HttpClient(CIO) { // HttpClientConfig<CIOEngineConfig>
* engine { // CIOEngineConfig.() -> Unit
* proxy = ProxyBuilder.http("proxy.example.com", 8080)
* }
* ```
*
* You can learn more from [Engines](https://ktor.io/docs/http-client-engines.html).
*/
Expand All @@ -40,11 +84,26 @@ public class HttpClientConfig<T : HttpClientEngineConfig> {
/**
* Specifies whether the client redirects to URLs provided in the `Location` header.
* You can disable redirections by setting this property to `false`.
*
* For the advanced redirection configuration, use [HttpRedirect] plugin.
*/
public var followRedirects: Boolean = true

/**
* Uses [defaultTransformers] to automatically handle simple [ContentType].
* Enable body transformations for many common types like [String], [ByteArray], [ByteReadChannel], etc.
* These transformations are applied to the request and response bodies.
*
* The transformers will be used when the response body is received with a type:
* ```kotlin
* val client = HttpClient()
* val bytes = client.get("https://ktor.io")
* .body<ByteArray>()
* ```
*
* The flag is enabled by default.
* You might want to disable it if you want to write your own transformers or handle body manually.
*
* Check [defaultTransformers] documentation for more details.
*/
public var useDefaultTransformers: Boolean = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import kotlin.coroutines.*

/**
* Callback that can be registered to listen for upload/download progress.
*
* This class is used for callbacks in [HttpRequestBuilder.onDownload] and [HttpRequestBuilder.onUpload].
*
* @param bytesSentTotal number of transmitted bytes.
* @param contentLength body size. Can be null if the size is unknown.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private val LOGGER = KtorSimpleLogger("io.ktor.client.plugins.defaultTransformer
* Usually installed by default so there is no need to use it
* unless you have disabled it via [HttpClientConfig.useDefaultTransformers].
*/
@OptIn(InternalAPI::class)
public fun HttpClient.defaultTransformers() {
requestPipeline.intercept(HttpRequestPipeline.Render) { body ->
if (context.headers[HttpHeaders.Accept] == null) {
Expand Down

0 comments on commit 2648fe3

Please sign in to comment.