Skip to content

Commit fd33bc0

Browse files
committed
chore: use ktor cio client engine everywhere execpt on jvm & dep updates
1 parent 5ae0d41 commit fd33bc0

File tree

10 files changed

+89
-41
lines changed

10 files changed

+89
-41
lines changed

backend/jvm/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ dependencies {
215215
implementation(libs.jte.runtime)
216216
// compileOnly(libs.jte.kotlin)
217217
implementation(libs.kotlinx.html)
218-
implementation(kotlinw("css"))
218+
implementation(libs.kotlin.wrappers.css)
219219
implementation(libs.ktor.server.html)
220220

221221
// OpenTelemetry

gradle/build-logic/src/main/kotlin/common/Multiplatform.kt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fun KotlinMultiplatformExtension.commonTarget(project: Project) =
4848
api(libs.kotlin.bignum)
4949
api(libs.kotlin.bignum.serialization)
5050
api(libs.ktor.client.core)
51+
api(libs.ktor.client.cio)
5152
api(libs.ktor.client.content.negotiation)
5253
api(libs.ktor.client.encoding)
5354
api(libs.ktor.client.logging)
@@ -189,9 +190,8 @@ fun KotlinMultiplatformExtension.jsTarget(project: Project) =
189190
sourceSets {
190191
jsMain {
191192
dependencies {
192-
api(libs.ktor.client.js)
193-
api(kotlinw("browser"))
194-
api(kotlinw("css"))
193+
api(libs.kotlin.wrappers.browser)
194+
api(libs.kotlin.wrappers.css)
195195
// api(npm("@js-joda/timezone", libs.versions.npm.jsjoda.tz.get()))
196196
// ksp(project(":meta:ksp:processor"))
197197
}
@@ -247,7 +247,6 @@ fun KotlinMultiplatformExtension.wasmJsTarget(project: Project) =
247247
dependencies {
248248
// kotlinx-browser is only supported for WasmJs.
249249
api(libs.kotlinx.browser)
250-
api(libs.ktor.client.js)
251250
// api(npm("@js-joda/timezone", libs.versions.npm.jsjoda.tz.get()))
252251
}
253252
}
@@ -301,14 +300,7 @@ fun KotlinMultiplatformExtension.nativeTargets(
301300
mingwX64 { configureAll() }
302301
}
303302

304-
sourceSets {
305-
nativeMain {
306-
dependencies {
307-
api(libs.ktor.client.cio)
308-
// api(libs.arrow.suspendapp.ktor)
309-
}
310-
}
311-
}
303+
sourceSets { nativeMain { dependencies { api(libs.ktor.client.curl) } } }
312304
}
313305
}
314306

gradle/build-logic/src/main/kotlin/common/ProjectExtns.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,6 @@ val Project.jvmRunArgs
337337
jvmArgs?.split(",") ?: jvmArguments(appRun = true)
338338
}
339339

340-
/**
341-
* Returns the dependency string for the specified Kotlin wrapper.
342-
*
343-
* @param target The target wrapper to retrieve the dependency string for.
344-
* @return The dependency string for the specified Kotlin wrapper.
345-
*/
346-
fun kotlinw(target: String) = "org.jetbrains.kotlin-wrappers:kotlin-$target"
347-
348340
// https://kotlinlang.org/docs/multiplatform-set-up-targets.html#distinguish-several-targets-for-one-platform
349341
val mppTargetAttr = Attribute.of("mpp.target.name", String::class.java)
350342

gradle/kotlin-js-store/package-lock.json

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ ktor-serialization-xml = { module = "io.ktor:ktor-serialization-ko
391391
ktor-client-core = { module = "io.ktor:ktor-client-core" , version.ref = "ktor"}
392392
ktor-client-cio = { module = "io.ktor:ktor-client-cio" , version.ref = "ktor"}
393393
ktor-client-java = { module = "io.ktor:ktor-client-java" , version.ref = "ktor"}
394+
ktor-client-curl = { module = "io.ktor:ktor-client-curl" , version.ref = "ktor"}
394395
ktor-client-js = { module = "io.ktor:ktor-client-js" , version.ref = "ktor"}
395396
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp" , version.ref = "ktor"}
396397
ktor-client-jetty = { module = "io.ktor:ktor-client-jetty" , version.ref = "ktor"}
@@ -559,6 +560,8 @@ java-keychain = { module = "pt.davidafsilva.apple:jkeycha
559560
webjars-xterm = { module = "org.webjars.npm:xterm" , version.ref = "webjars-xterm" }
560561

561562
kotlin-wrappers-bom = { module = "org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom" , version.ref = "kotlin-wrappers" }
563+
kotlin-wrappers-browser = { module = "org.jetbrains.kotlin-wrappers:kotlin-browser" , version.ref = "kotlin-wrappers" }
564+
kotlin-wrappers-css = { module = "org.jetbrains.kotlin-wrappers:kotlin-css" , version.ref = "kotlin-wrappers" }
562565
multiplatform-settings-core = { module = "com.russhwolf:multiplatform-settings" , version.ref = "kmp-settings" }
563566
multiplatform-settings-coroutines = { module = "com.russhwolf:multiplatform-settings-coroutines" , version.ref = "kmp-settings" }
564567
multiplatform-settings-no-arg = { module = "com.russhwolf:multiplatform-settings-no-arg" , version.ref = "kmp-settings" }

shared/src/commonMain/kotlin/dev/suresh/http/HttpClient.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ val json by lazy {
3333
}
3434
}
3535

36-
/** Multiplatform HTTP client factory function. */
36+
/**
37+
* Multiplatform HTTP client engine configuration
38+
*
39+
* See [doc](https://ktor.io/docs/client-engines.html#mpp-config) for more details.
40+
*/
3741
expect fun httpClient(
3842
name: String = "Api Client",
3943
timeout: Timeout = Timeout.DEFAULT,
@@ -81,7 +85,10 @@ expect fun httpClient(
8185
sanitizeHeader { header -> header == HttpHeaders.Authorization }
8286
}
8387

84-
engine { pipelining = true }
88+
engine {
89+
pipelining = true
90+
// proxy = ProxyBuilder.http()
91+
}
8592

8693
followRedirects = true
8794

shared/src/jsMain/kotlin/dev/suresh/http/HttpClient.js.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@ package dev.suresh.http
22

33
import io.github.oshai.kotlinlogging.KLogger
44
import io.ktor.client.*
5-
import io.ktor.client.engine.js.*
5+
import io.ktor.client.engine.cio.*
66

77
actual fun httpClient(
88
name: String,
99
timeout: Timeout,
1010
retry: Retry,
1111
httpLogger: KLogger,
1212
config: HttpClientConfig<*>.() -> Unit
13-
) = HttpClient(Js) { config(this) }
13+
) =
14+
HttpClient(CIO) {
15+
config(this)
16+
engine {
17+
maxConnectionsCount = 1000
18+
endpoint {
19+
maxConnectionsPerRoute = 100
20+
pipelineMaxSize = 20
21+
keepAliveTime = 5000
22+
connectTimeout = 5000
23+
connectAttempts = 5
24+
}
25+
}
26+
}

shared/src/jvmMain/kotlin/dev/suresh/http/HttpClient.jvm.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,25 @@ actual fun httpClient(
3030
config(this)
3131
engine { config { sslContext(customSSLFactory.sslContext) } }
3232
}
33+
34+
// val cioHttpClient = HttpClient(CIO) {
35+
// config(this)
36+
//
37+
// engine {
38+
// maxConnectionsCount = 1000
39+
// endpoint {
40+
// maxConnectionsPerRoute = 100
41+
// pipelineMaxSize = 20
42+
// keepAliveTime = 5000
43+
// connectTimeout = 5000
44+
// connectAttempts = 5
45+
// }
46+
// https {
47+
// serverName = "suresh.dev"
48+
// cipherSuites = CIOCipherSuites.SupportedSuites
49+
// trustManager = myCustomTrustManager
50+
// random = mySecureRandom
51+
// addKeyStore(myKeyStore, myKeyStorePassword)
52+
// }
53+
// }
54+
// }

shared/src/nativeMain/kotlin/dev/suresh/http/HttpClient.native.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package dev.suresh.http
22

33
import io.github.oshai.kotlinlogging.KLogger
44
import io.ktor.client.*
5-
import io.ktor.client.engine.cio.*
5+
import io.ktor.client.engine.curl.*
66

77
actual fun httpClient(
88
name: String,
99
timeout: Timeout,
1010
retry: Retry,
1111
httpLogger: KLogger,
1212
config: HttpClientConfig<*>.() -> Unit
13-
) = HttpClient(CIO) { config(this) }
13+
) =
14+
HttpClient(Curl) {
15+
config(this)
16+
engine { sslVerify = true }
17+
}

shared/src/wasmJsMain/kotlin/dev/suresh/http/HttpClient.wasmJs.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@ package dev.suresh.http
22

33
import io.github.oshai.kotlinlogging.KLogger
44
import io.ktor.client.*
5-
import io.ktor.client.engine.js.*
5+
import io.ktor.client.engine.cio.*
66

77
actual fun httpClient(
88
name: String,
99
timeout: Timeout,
1010
retry: Retry,
1111
httpLogger: KLogger,
1212
config: HttpClientConfig<*>.() -> Unit,
13-
) = HttpClient(Js) { config(this) }
13+
) =
14+
HttpClient(CIO) {
15+
config(this)
16+
engine {
17+
maxConnectionsCount = 1000
18+
endpoint {
19+
maxConnectionsPerRoute = 100
20+
pipelineMaxSize = 20
21+
keepAliveTime = 5000
22+
connectTimeout = 5000
23+
connectAttempts = 5
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)