From c2cb57635c4ead763635473c825f7559c1f5bd48 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jan 2019 11:49:27 +0800 Subject: [PATCH] refactoring and fixes --- gradle.properties | 2 +- .../TelegramBotAPI/bot/Ktor/ProxySettings.kt | 5 +++-- .../insanusmokrassar/TelegramBotAPI/bot/ProxySettings.kt | 1 + .../TelegramBotAPI/bot/settings/limiters/PowLimiter.kt | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index dc6da056e3..209f0390f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,6 @@ kotlin_version=1.3.11 kotlin_coroutines_version=1.1.0 kotlin_serialisation_runtime_version=0.9.1 joda_time_version=2.10.1 -ktor_version=1.0.1 +ktor_version=1.1.1 gradle_bintray_plugin_version=1.8.4 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/ProxySettings.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/ProxySettings.kt index 9316112d72..745c4ecdf8 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/ProxySettings.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/ProxySettings.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor -import com.github.insanusmokrassar.TelegramBotAPI.bot.ProxySettings +import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.ProxySettings +import io.ktor.http.HttpHeaders import okhttp3.Credentials import okhttp3.OkHttpClient import java.net.InetSocketAddress @@ -22,7 +23,7 @@ fun OkHttpClient.Builder.useWith(proxySettings: ProxySettings) { _, response -> response.request().newBuilder().apply { addHeader( - "Proxy-Authorization", + HttpHeaders.ProxyAuthorization, Credentials.basic(proxySettings.username ?: "", password) ) }.build() diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/ProxySettings.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/ProxySettings.kt index afbe01c957..12e3ab9e71 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/ProxySettings.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/ProxySettings.kt @@ -1,6 +1,7 @@ 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( diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/settings/limiters/PowLimiter.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/settings/limiters/PowLimiter.kt index d20bbc194d..d18c600e9c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/settings/limiters/PowLimiter.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/settings/limiters/PowLimiter.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.serialization.Optional import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient import java.util.concurrent.Executors import kotlin.coroutines.* @@ -24,10 +25,13 @@ data class PowLimiter( @Optional private val powK: Double = 0.0016 ) : RequestLimiter { + @Transient private val scope = CoroutineScope( Executors.newFixedThreadPool(3).asCoroutineDispatcher() ) + @Transient private val eventsChannel = Channel(Channel.UNLIMITED) + @Transient private val awaitTimeRange = minAwaitTime .. maxAwaitTime init {