From 82420165d0a24bd16ef38ee3d53fcd6dd2fafc59 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 24 Jan 2019 08:37:39 +0800 Subject: [PATCH] replace "useWith" and rename file of BaseRequestsExecutor --- CHANGELOG | 3 ++ ...stsExecutor.kt => BaseRequestsExecutor.kt} | 0 .../TelegramBotAPI/bot/Ktor/ProxySettings.kt | 31 +++++++++++++++++ .../TelegramBotAPI/bot/ProxySettings.kt | 33 ++++--------------- 4 files changed, 41 insertions(+), 26 deletions(-) rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/{DefaultRequestsExecutor.kt => BaseRequestsExecutor.kt} (100%) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/ProxySettings.kt diff --git a/CHANGELOG b/CHANGELOG index 811a0aea26..96762ecf16 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -44,3 +44,6 @@ * Fix default realisation of MessageEntity#asMarkdownSource ### 0.9.0 + +* Old extension `OkHttpClient.Builder#useWith` now deprecated and must be replaced by the same in +`com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor` package diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/DefaultRequestsExecutor.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/BaseRequestsExecutor.kt similarity index 100% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/DefaultRequestsExecutor.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/BaseRequestsExecutor.kt 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 new file mode 100644 index 0000000000..9316112d72 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/Ktor/ProxySettings.kt @@ -0,0 +1,31 @@ +package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor + +import com.github.insanusmokrassar.TelegramBotAPI.bot.ProxySettings +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( + "Proxy-Authorization", + 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 1023292e76..a137983f62 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/ProxySettings.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/ProxySettings.kt @@ -1,9 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot -import okhttp3.Credentials +import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.useWith import okhttp3.OkHttpClient -import java.net.InetSocketAddress -import java.net.Proxy data class ProxySettings( val host: String = "localhost", @@ -12,26 +10,9 @@ data class ProxySettings( val password: String? = null ) -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( - "Proxy-Authorization", - Credentials.basic(proxySettings.username ?: "", password) - ) - }.build() - } - } -} + +@Deprecated( + "Replaced in Ktor package", + ReplaceWith("useWith", "com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.useWith") +) +fun OkHttpClient.Builder.useWith(proxySettings: ProxySettings) = useWith(proxySettings)