1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2026-01-12 08:19:16 +00:00

MultipleClientKtorRequestsExecutor, DefaultKtorRequestsExecutor, KtorRequestsExecutor as expect class

This commit is contained in:
2023-04-18 03:13:41 +06:00
parent 2778315aed
commit cd6f4831ae
20 changed files with 432 additions and 134 deletions

View File

@@ -0,0 +1 @@
package dev.inmo.tgbotapi

View File

@@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.bot.ktor
import dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor
actual typealias KtorRequestsExecutor = MultipleClientKtorRequestsExecutor

View File

@@ -0,0 +1,24 @@
package dev.inmo.tgbotapi.bot.ktor.base
import io.ktor.client.*
import io.ktor.client.engine.curl.*
/**
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
* platforms should return [client]
*
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
*
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
* on MingwX64
*/
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? CurlClientEngineConfig) ?.let {
lateinit var config: HttpClientConfig<out CurlClientEngineConfig>
client.config {
config = this as HttpClientConfig<out CurlClientEngineConfig>
}.close()
HttpClient(Curl) {
this.plusAssign(config)
}
} ?: throw IllegalArgumentException("On LinuxX64 TelegramBotAPI currently support only Curl Ktor HttpClient engine")