Ktor CIO Client Proxy

This commit is contained in:
tarsin committed 2023-02-04 13:49:22 +08:00
1 parent 67c529ffe9
commit 4419ab154b
1 file changed
+16
@@ -63,6 +63,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import java.net.InetAddress
import java.net.InetSocketAddress
import java.net.Proxy
import java.security.KeyStore
import java.util.Arrays
@@ -319,6 +321,20 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
val ktorClient by lazy {
HttpClient(CIO) {
engine {
proxy = when (Settings.getProxyType()) {
EhProxySelector.TYPE_DIRECT -> Proxy.NO_PROXY
EhProxySelector.TYPE_SYSTEM -> null
EhProxySelector.TYPE_HTTP -> {
val ip = Settings.getProxyIp()
val port = Settings.getProxyPort()
val iNetAddress = InetAddress.getByName(ip)
val socketAddress = InetSocketAddress(iNetAddress, port)
Proxy(Proxy.Type.HTTP, socketAddress)
}
// CIO does not support Socks proxy yet
else -> null
}
https {
serverName = "0.0.0.0".takeIf { Settings.getDF() }
trustManager = EhX509TrustManager