From 82de49c5ddca04b9ce15f91226900afa55133b42 Mon Sep 17 00:00:00 2001 From: Fabian Schedler Date: Sat, 17 Feb 2024 20:37:15 +0100 Subject: [PATCH] Increase timeout and add ContentEncoding to HttpClient --- gradle/libs.versions.toml | 1 + shared/build.gradle.kts | 1 + .../waiterrobot/shared/core/data/api/BasicClient.kt | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 37507c5..1e2fb8a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -81,6 +81,7 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" } ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" } +ktor-client-content-encoding = { module = "io.ktor:ktor-client-encoding", version.ref = "ktor" } ktor-client-auth = { module = "io.ktor:ktor-client-auth", version.ref = "ktor" } ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" } ktor-client-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 9b5eecd..4e82aa5 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -68,6 +68,7 @@ kotlin { // Ktor (HTTP client) implementation(libs.ktor.client.core) + implementation(libs.ktor.client.content.encoding) implementation(libs.ktor.client.content.negotiation) implementation(libs.ktor.client.serialization.json) implementation(libs.ktor.client.auth) diff --git a/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/data/api/BasicClient.kt b/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/data/api/BasicClient.kt index fd1df50..8c8a7a1 100644 --- a/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/data/api/BasicClient.kt +++ b/shared/src/commonMain/kotlin/org/datepollsystems/waiterrobot/shared/core/data/api/BasicClient.kt @@ -3,6 +3,7 @@ package org.datepollsystems.waiterrobot.shared.core.data.api import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig import io.ktor.client.plugins.HttpTimeout +import io.ktor.client.plugins.compression.ContentEncoding import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.client.plugins.defaultRequest import io.ktor.client.plugins.logging.LogLevel @@ -26,13 +27,19 @@ internal fun HttpClientConfig<*>.commonConfig( ktorLogger: KtorLogger, enableNetworkLogs: Boolean ) { + install(ContentEncoding) { + deflate(1.0f) + @Suppress("MagicNumber") + gzip(0.9f) + } + install(ContentNegotiation) { json(json) } install(HttpTimeout) { @Suppress("MagicNumber") - requestTimeoutMillis = 10_000 + requestTimeoutMillis = 15_000 } if (enableNetworkLogs) {