Skip to content

Commit 59cb175

Browse files
committed
Use different ktor implementation for JS
Signed-off-by: Bence Hornák <[email protected]>
1 parent fe27c90 commit 59cb175

File tree

5 files changed

+54
-17
lines changed

5 files changed

+54
-17
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ktor = "3.1.3"
88
[libraries]
99
ktor-core = { module="io.ktor:ktor-client-core", version.ref="ktor" }
1010
ktor-cio = { module="io.ktor:ktor-client-cio", version.ref="ktor" }
11+
ktor-js = { module="io.ktor:ktor-client-js", version.ref="ktor" }
1112
ktor-client-content-negotiation = { module="io.ktor:ktor-client-content-negotiation", version.ref="ktor" }
1213
ktor-serialization-kotlinx-json = { module="io.ktor:ktor-serialization-kotlinx-json", version.ref="ktor" }
1314
ktor-client-mock = { module="io.ktor:ktor-client-mock", version.ref="ktor" }

providers/ofrep/build.gradle.kts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,39 @@ kotlin {
3434
}
3535

3636
sourceSets {
37-
commonMain.dependencies {
38-
api(libs.openfeature.kotlin.sdk)
37+
val commonMain by getting {
38+
dependencies {
39+
api(libs.openfeature.kotlin.sdk)
3940

40-
api(libs.kotlinx.coroutines.core)
41-
api(libs.ktor.core)
42-
implementation(libs.ktor.cio)
43-
implementation(libs.ktor.client.content.negotiation)
44-
implementation(libs.ktor.serialization.kotlinx.json)
41+
api(libs.kotlinx.coroutines.core)
42+
api(libs.ktor.core)
43+
implementation(libs.ktor.client.content.negotiation)
44+
implementation(libs.ktor.serialization.kotlinx.json)
45+
}
4546
}
4647
commonTest.dependencies {
4748
implementation(libs.kotlin.test)
4849
implementation(libs.kotlinx.coroutines.test)
4950
implementation(libs.ktor.client.mock)
5051
}
52+
val nonJsMain by creating {
53+
dependsOn(commonMain)
54+
dependencies {
55+
implementation(libs.ktor.cio)
56+
}
57+
}
58+
androidMain {
59+
dependsOn(nonJsMain)
60+
}
61+
jvmMain {
62+
dependsOn(nonJsMain)
63+
}
64+
linuxX64Main {
65+
dependsOn(nonJsMain)
66+
}
67+
jsMain.dependencies {
68+
implementation(libs.ktor.js)
69+
}
5170
}
5271
}
5372

providers/ofrep/src/commonMain/kotlin/dev/openfeature/kotlin/contrib/providers/ofrep/bean/Http.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@ package dev.openfeature.kotlin.contrib.providers.ofrep.bean
22

33
import io.ktor.client.HttpClient
44
import io.ktor.client.engine.HttpClientEngine
5-
import io.ktor.client.engine.cio.CIO
6-
import io.ktor.client.engine.cio.endpoint
75
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
86
import io.ktor.serialization.kotlinx.json.json
97

10-
private fun defaultHttpEngine(options: OfrepOptions): HttpClientEngine =
11-
CIO.create {
12-
maxConnectionsCount = options.maxIdleConnections
13-
endpoint {
14-
keepAliveTime = options.keepAliveDuration.inWholeMilliseconds
15-
connectTimeout = options.timeout.inWholeMilliseconds
16-
}
17-
}
8+
internal expect fun defaultHttpEngine(options: OfrepOptions): HttpClientEngine
189

1910
internal fun createHttpClient(options: OfrepOptions): HttpClient {
2011
val httpEngine = options.httpClientEngine ?: defaultHttpEngine(options)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package dev.openfeature.kotlin.contrib.providers.ofrep.bean
2+
3+
import io.ktor.client.engine.HttpClientEngine
4+
import io.ktor.client.engine.js.Js
5+
6+
internal actual fun defaultHttpEngine(options: OfrepOptions): HttpClientEngine =
7+
Js.create {
8+
// TODO: consider the following options:
9+
// - options.maxIdleConnections
10+
// - options.keepAliveDuration
11+
// - options.timeout
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dev.openfeature.kotlin.contrib.providers.ofrep.bean
2+
3+
import io.ktor.client.engine.HttpClientEngine
4+
import io.ktor.client.engine.cio.CIO
5+
import io.ktor.client.engine.cio.endpoint
6+
7+
internal actual fun defaultHttpEngine(options: OfrepOptions): HttpClientEngine =
8+
CIO.create {
9+
maxConnectionsCount = options.maxIdleConnections
10+
endpoint {
11+
keepAliveTime = options.keepAliveDuration.inWholeMilliseconds
12+
connectTimeout = options.timeout.inWholeMilliseconds
13+
}
14+
}

0 commit comments

Comments
 (0)