mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-21 06:45:46 +00:00
commonly of webhooks and other requests-related code
This commit is contained in:
@@ -12,7 +12,6 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.util.cio.toByteArray
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.io.charsets.Charset
|
||||
@@ -20,7 +19,7 @@ import kotlinx.serialization.json.Json
|
||||
|
||||
class KtorRequestsExecutor(
|
||||
token: String,
|
||||
private val client: HttpClient = HttpClient(OkHttp),
|
||||
private val client: HttpClient = HttpClient(),
|
||||
hostUrl: String = "https://api.telegram.org",
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false,
|
||||
@@ -29,11 +28,11 @@ class KtorRequestsExecutor(
|
||||
) : BaseRequestsExecutor(token, hostUrl) {
|
||||
constructor(
|
||||
token: String,
|
||||
engine: HttpClientEngine = OkHttp.create(),
|
||||
engine: HttpClientEngine? = null,
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
) : this(
|
||||
token,
|
||||
HttpClient(engine),
|
||||
engine ?.let { HttpClient(engine) } ?: HttpClient(),
|
||||
hostUrl
|
||||
)
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.ProxySettings
|
||||
import io.ktor.http.HttpHeaders
|
||||
import okhttp3.Credentials
|
||||
import okhttp3.OkHttpClient
|
||||
import java.net.InetSocketAddress
|
||||
import java.net.Proxy
|
||||
|
||||
fun OkHttpClient.Builder.useWith(proxySettings: ProxySettings) {
|
||||
proxy(
|
||||
Proxy(
|
||||
Proxy.Type.SOCKS,
|
||||
InetSocketAddress(
|
||||
proxySettings.host,
|
||||
proxySettings.port
|
||||
)
|
||||
)
|
||||
)
|
||||
proxySettings.password ?.let {
|
||||
password ->
|
||||
proxyAuthenticator {
|
||||
_, response ->
|
||||
response.request().newBuilder().apply {
|
||||
addHeader(
|
||||
HttpHeaders.ProxyAuthorization,
|
||||
Credentials.basic(proxySettings.username ?: "", password)
|
||||
)
|
||||
}.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.useWith
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.ProxySettings
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
@Deprecated(
|
||||
"Replaced in settings package",
|
||||
ReplaceWith("ProxySettings", "com.github.insanusmokrassar.TelegramBotAPI.bot.settings.ProxySettings")
|
||||
)
|
||||
typealias ProxySettings = com.github.insanusmokrassar.TelegramBotAPI.bot.settings.ProxySettings
|
||||
|
||||
|
||||
@Deprecated(
|
||||
"Replaced in Ktor package",
|
||||
ReplaceWith("useWith", "com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.useWith")
|
||||
)
|
||||
fun OkHttpClient.Builder.useWith(proxySettings: ProxySettings) = useWith(proxySettings)
|
||||
Reference in New Issue
Block a user