From e2b4424ec4e8b057ac6896dd918ce0c97835727c Mon Sep 17 00:00:00 2001 From: Alexey Illarionov Date: Fri, 8 Nov 2024 02:34:27 +0300 Subject: [PATCH] Bumpd ktor to 3.0.1 (#148) --- gradle/libs.versions.toml | 2 +- .../src/commonMain/kotlin/HttpStatementExt.kt | 17 +++++++++-------- .../jvmTest/kotlin/RealKtorNetworkTestClient.kt | 1 - .../src/jvmTest/kotlin/integration/KtorExt.kt | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 58b1e76..031f2aa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,7 +19,7 @@ kotlinpoet = "2.0.0" kotlinx-binary-compatibility-validator = "0.16.3" kotlinx-coroutines = "1.9.0" kotlinx-serialization = "1.7.3" -ktor = "2.3.12" +ktor = "3.0.1" okhttp3 = "4.12.0" okhttp5 = "5.0.0-alpha.14" okio = "3.9.1" diff --git a/igdbclient-ktor/src/commonMain/kotlin/HttpStatementExt.kt b/igdbclient-ktor/src/commonMain/kotlin/HttpStatementExt.kt index bad7c54..aaf5b91 100644 --- a/igdbclient-ktor/src/commonMain/kotlin/HttpStatementExt.kt +++ b/igdbclient-ktor/src/commonMain/kotlin/HttpStatementExt.kt @@ -5,22 +5,23 @@ package ru.pixnews.igdbclient.ktor -import io.ktor.client.call.body import io.ktor.client.statement.HttpResponse import io.ktor.client.statement.HttpStatement +import io.ktor.client.statement.bodyAsChannel import io.ktor.util.flattenEntries import io.ktor.utils.io.ByteReadChannel -import io.ktor.utils.io.core.isEmpty -import io.ktor.utils.io.core.readBytes -import io.ktor.utils.io.errors.IOException +import io.ktor.utils.io.readRemaining import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import kotlinx.io.IOException +import kotlinx.io.readByteArray import okio.Buffer import okio.BufferedSource import okio.use import ru.pixnews.igdbclient.IgdbResult import ru.pixnews.igdbclient.ktor.KtorIgdbConstants.DEFAULT_BUFFER_SIZE +import kotlinx.io.Source as kotlinxSource internal suspend fun HttpStatement.executeAsyncWithResult( backgroundDispatcher: CoroutineDispatcher = Dispatchers.Default, @@ -51,13 +52,13 @@ private suspend fun readHttpResponse( successResponseParser: (BufferedSource) -> T, errorResponseParser: (BufferedSource) -> E, ): IgdbResult { - val channel: ByteReadChannel = response.body() + val channel: ByteReadChannel = response.bodyAsChannel() val responseBody = Buffer() while (!channel.isClosedForRead) { - val packet = channel.readRemaining(DEFAULT_BUFFER_SIZE) - while (!packet.isEmpty) { - val bytes = packet.readBytes() + val packet: kotlinxSource = channel.readRemaining(DEFAULT_BUFFER_SIZE) + while (!packet.exhausted()) { + val bytes = packet.readByteArray() responseBody.write(bytes) } } diff --git a/igdbclient-ktor/src/jvmTest/kotlin/RealKtorNetworkTestClient.kt b/igdbclient-ktor/src/jvmTest/kotlin/RealKtorNetworkTestClient.kt index 23094e5..09adaad 100644 --- a/igdbclient-ktor/src/jvmTest/kotlin/RealKtorNetworkTestClient.kt +++ b/igdbclient-ktor/src/jvmTest/kotlin/RealKtorNetworkTestClient.kt @@ -64,7 +64,6 @@ class RealKtorNetworkTestClient { var coroutinesExt: MainCoroutineExtension = MainCoroutineExtension() val testTokenProperties = TestTokenProperties.loadFromResources() private val ktorHttpClient: HttpClient = HttpClient(Java) { - developmentMode = true install(Logging) { logger = IgdbKtorLogger() level = LogLevel.ALL diff --git a/igdbclient-ktor/src/jvmTest/kotlin/integration/KtorExt.kt b/igdbclient-ktor/src/jvmTest/kotlin/integration/KtorExt.kt index 4bedec8..dbd7eb5 100644 --- a/igdbclient-ktor/src/jvmTest/kotlin/integration/KtorExt.kt +++ b/igdbclient-ktor/src/jvmTest/kotlin/integration/KtorExt.kt @@ -17,7 +17,6 @@ import io.ktor.client.plugins.logging.Logger as KtorLogger internal fun HttpClientConfig<*>.applyTestDefaults( @Suppress("NewApi") timeout: Duration = Duration.ofMillis(2000), ) { - developmentMode = true install(HttpTimeout) { connectTimeoutMillis = timeout.toMillis() socketTimeoutMillis = timeout.toMillis()