mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
replace "useWith" and rename file of BaseRequestsExecutor
This commit is contained in:
parent
a788ea76f1
commit
82420165d0
@ -44,3 +44,6 @@
|
|||||||
* Fix default realisation of MessageEntity#asMarkdownSource
|
* Fix default realisation of MessageEntity#asMarkdownSource
|
||||||
|
|
||||||
### 0.9.0
|
### 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
|
||||||
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||||
|
|
||||||
import okhttp3.Credentials
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.useWith
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import java.net.InetSocketAddress
|
|
||||||
import java.net.Proxy
|
|
||||||
|
|
||||||
data class ProxySettings(
|
data class ProxySettings(
|
||||||
val host: String = "localhost",
|
val host: String = "localhost",
|
||||||
@ -12,26 +10,9 @@ data class ProxySettings(
|
|||||||
val password: String? = null
|
val password: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
fun OkHttpClient.Builder.useWith(proxySettings: ProxySettings) {
|
|
||||||
proxy(
|
@Deprecated(
|
||||||
Proxy(
|
"Replaced in Ktor package",
|
||||||
Proxy.Type.SOCKS,
|
ReplaceWith("useWith", "com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.useWith")
|
||||||
InetSocketAddress(
|
)
|
||||||
proxySettings.host,
|
fun OkHttpClient.Builder.useWith(proxySettings: ProxySettings) = useWith(proxySettings)
|
||||||
proxySettings.port
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
proxySettings.password ?.let {
|
|
||||||
password ->
|
|
||||||
proxyAuthenticator {
|
|
||||||
_, response ->
|
|
||||||
response.request().newBuilder().apply {
|
|
||||||
addHeader(
|
|
||||||
"Proxy-Authorization",
|
|
||||||
Credentials.basic(proxySettings.username ?: "", password)
|
|
||||||
)
|
|
||||||
}.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user