diff --git a/account/build.gradle.kts b/account/build.gradle.kts index 58df1e5..da81f67 100644 --- a/account/build.gradle.kts +++ b/account/build.gradle.kts @@ -38,7 +38,7 @@ android { @OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class) kotlin { group = "com.kape.android" - version = "1.4.6" + version = "1.4.7" // Enable the default target hierarchy. // It's a template for all possible targets and their shared source sets hardcoded in the diff --git a/account/src/androidMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt b/account/src/androidMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt index dd49bea..b66ff2f 100644 --- a/account/src/androidMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt +++ b/account/src/androidMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt @@ -41,7 +41,8 @@ internal actual object AccountHttpClient { actual fun client( certificate: String?, - pinnedEndpoint: Pair? + pinnedEndpoint: Pair?, + requestTimeoutMillis: Long ) : Pair { var httpClient: HttpClient? = null var exception: Exception? = null @@ -49,7 +50,7 @@ internal actual object AccountHttpClient { httpClient = HttpClient(OkHttp) { expectSuccess = false install(HttpTimeout) { - requestTimeoutMillis = Account.REQUEST_TIMEOUT_MS + this.requestTimeoutMillis = requestTimeoutMillis } if (certificate != null && pinnedEndpoint != null) { diff --git a/account/src/commonMain/kotlin/com/privateinternetaccess/account/AccountAPI.kt b/account/src/commonMain/kotlin/com/privateinternetaccess/account/AccountAPI.kt index 3c8749a..e334082 100644 --- a/account/src/commonMain/kotlin/com/privateinternetaccess/account/AccountAPI.kt +++ b/account/src/commonMain/kotlin/com/privateinternetaccess/account/AccountAPI.kt @@ -18,6 +18,7 @@ package com.privateinternetaccess.account +import com.privateinternetaccess.account.internals.Account import com.privateinternetaccess.account.internals.AndroidAccount import com.privateinternetaccess.account.internals.IOSAccount import com.privateinternetaccess.account.model.request.AmazonSignupInformation @@ -109,9 +110,13 @@ public interface AccountAPI { ) /** + * @param requestTimeoutMillis `Long` * @param callback `(status: ClientStatusInformation?, error: List) -> Unit` */ - fun clientStatus(callback: (status: ClientStatusInformation?, error: List) -> Unit) + fun clientStatus( + requestTimeoutMillis: Long = Account.REQUEST_TIMEOUT_MS, + callback: (status: ClientStatusInformation?, error: List) -> Unit, + ) /** * @param email `String` diff --git a/account/src/commonMain/kotlin/com/privateinternetaccess/account/internals/Account.kt b/account/src/commonMain/kotlin/com/privateinternetaccess/account/internals/Account.kt index e0c55c7..924c148 100644 --- a/account/src/commonMain/kotlin/com/privateinternetaccess/account/internals/Account.kt +++ b/account/src/commonMain/kotlin/com/privateinternetaccess/account/internals/Account.kt @@ -53,7 +53,8 @@ internal expect object AccountHttpClient { */ fun client( certificate: String? = null, - pinnedEndpoint: Pair? = null + pinnedEndpoint: Pair? = null, + requestTimeoutMillis: Long = Account.REQUEST_TIMEOUT_MS ): Pair } @@ -221,10 +222,12 @@ internal open class Account( } override fun clientStatus( + requestTimeoutMillis: Long, callback: (status: ClientStatusInformation?, error: List) -> Unit + ) { launch { - clientStatusAsync(endpointsProvider.accountEndpoints(), callback) + clientStatusAsync(endpointsProvider.accountEndpoints(), callback, requestTimeoutMillis) } } @@ -967,7 +970,8 @@ internal open class Account( private suspend fun clientStatusAsync( endpoints: List, - callback: (status: ClientStatusInformation?, error: List) -> Unit + callback: (status: ClientStatusInformation?, error: List) -> Unit, + requestTimeoutMillis: Long ) { var clientStatus: ClientStatusInformation? = null val listErrors: MutableList = mutableListOf() @@ -994,9 +998,9 @@ internal open class Account( } val httpClientConfigResult = if (endpoint.usePinnedCertificate) { - AccountHttpClient.client(certificate, Pair(endpoint.ipOrRootDomain, endpoint.certificateCommonName!!)) + AccountHttpClient.client(certificate, Pair(endpoint.ipOrRootDomain, endpoint.certificateCommonName!!), requestTimeoutMillis) } else { - AccountHttpClient.client() + AccountHttpClient.client(requestTimeoutMillis = requestTimeoutMillis) } val httpClient = httpClientConfigResult.first diff --git a/account/src/iosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt b/account/src/iosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt index 1084fbb..b4905bc 100644 --- a/account/src/iosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt +++ b/account/src/iosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt @@ -23,6 +23,7 @@ import io.ktor.client.engine.darwin.* import io.ktor.client.engine.ios.Ios import io.ktor.client.plugins.* import io.ktor.client.engine.ios.* +import io.ktor.client.request.request import kotlinx.cinterop.* import platform.CoreFoundation.* import platform.Foundation.* @@ -33,12 +34,13 @@ internal actual object AccountHttpClient { actual fun client( certificate: String?, - pinnedEndpoint: Pair? + pinnedEndpoint: Pair?, + requestTimeoutMillis: Long ): Pair { return Pair(HttpClient(Darwin) { expectSuccess = false install(HttpTimeout) { - requestTimeoutMillis = Account.REQUEST_TIMEOUT_MS + this.requestTimeoutMillis = requestTimeoutMillis } if (certificate != null && pinnedEndpoint != null) { diff --git a/account/src/tvosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt b/account/src/tvosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt index e26bcab..8a4463e 100644 --- a/account/src/tvosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt +++ b/account/src/tvosMain/kotlin/com/privateinternetaccess/account/internals/AccountHttpClient.kt @@ -31,12 +31,13 @@ internal actual object AccountHttpClient { actual fun client( certificate: String?, - pinnedEndpoint: Pair? + pinnedEndpoint: Pair?, + requestTimeoutMillis: Long ): Pair { return Pair(HttpClient(Darwin) { expectSuccess = false install(HttpTimeout) { - requestTimeoutMillis = Account.REQUEST_TIMEOUT_MS + this.requestTimeoutMillis = requestTimeoutMillis } if (certificate != null && pinnedEndpoint != null) {