replace "useWith" and rename file of BaseRequestsExecutor

This commit is contained in:
InsanusMokrassar 2019-01-24 08:37:39 +08:00
parent a788ea76f1
commit 82420165d0
4 changed files with 41 additions and 26 deletions

View File

@ -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

View File

@ -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()
}
}
}

View File

@ -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)