Skip to content

Commit

Permalink
Bumpd ktor to 3.0.1 (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
illarionov authored Nov 7, 2024
1 parent 80827be commit e2b4424
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 9 additions & 8 deletions igdbclient-ktor/src/commonMain/kotlin/HttpStatementExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T : Any, E : Any> HttpStatement.executeAsyncWithResult(
backgroundDispatcher: CoroutineDispatcher = Dispatchers.Default,
Expand Down Expand Up @@ -51,13 +52,13 @@ private suspend fun <T : Any, E : Any> readHttpResponse(
successResponseParser: (BufferedSource) -> T,
errorResponseParser: (BufferedSource) -> E,
): IgdbResult<T, E> {
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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion igdbclient-ktor/src/jvmTest/kotlin/integration/KtorExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e2b4424

Please sign in to comment.