|
|
@ -4,13 +4,7 @@ import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.help.config.AppConfig |
|
|
|
import io.legado.app.help.config.AppConfig |
|
|
|
import io.legado.app.help.http.cronet.CronetInterceptor |
|
|
|
import io.legado.app.help.http.cronet.CronetInterceptor |
|
|
|
import io.legado.app.help.http.cronet.CronetLoader |
|
|
|
import io.legado.app.help.http.cronet.CronetLoader |
|
|
|
import okhttp3.ConnectionSpec |
|
|
|
import okhttp3.* |
|
|
|
import okhttp3.Credentials |
|
|
|
|
|
|
|
import okhttp3.CookieJar |
|
|
|
|
|
|
|
import okhttp3.Cookie |
|
|
|
|
|
|
|
import okhttp3.HttpUrl |
|
|
|
|
|
|
|
import okhttp3.Interceptor |
|
|
|
|
|
|
|
import okhttp3.OkHttpClient |
|
|
|
|
|
|
|
import java.net.InetSocketAddress |
|
|
|
import java.net.InetSocketAddress |
|
|
|
import java.net.Proxy |
|
|
|
import java.net.Proxy |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
@ -20,6 +14,22 @@ private val proxyClientCache: ConcurrentHashMap<String, OkHttpClient> by lazy { |
|
|
|
ConcurrentHashMap() |
|
|
|
ConcurrentHashMap() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val cookieJar by lazy { |
|
|
|
|
|
|
|
object : CookieJar { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun loadForRequest(url: HttpUrl): List<Cookie> { |
|
|
|
|
|
|
|
return emptyList() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) { |
|
|
|
|
|
|
|
cookies.forEach { |
|
|
|
|
|
|
|
CookieStore.replaceCookie(url.toString(), "${it.name}=${it.value}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val okHttpClient: OkHttpClient by lazy { |
|
|
|
val okHttpClient: OkHttpClient by lazy { |
|
|
|
val specs = arrayListOf( |
|
|
|
val specs = arrayListOf( |
|
|
|
ConnectionSpec.MODERN_TLS, |
|
|
|
ConnectionSpec.MODERN_TLS, |
|
|
@ -32,16 +42,7 @@ val okHttpClient: OkHttpClient by lazy { |
|
|
|
.writeTimeout(15, TimeUnit.SECONDS) |
|
|
|
.writeTimeout(15, TimeUnit.SECONDS) |
|
|
|
.readTimeout(15, TimeUnit.SECONDS) |
|
|
|
.readTimeout(15, TimeUnit.SECONDS) |
|
|
|
.callTimeout(60, TimeUnit.SECONDS) |
|
|
|
.callTimeout(60, TimeUnit.SECONDS) |
|
|
|
.cookieJar(object : CookieJar { |
|
|
|
.cookieJar(cookieJar = cookieJar) |
|
|
|
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) { |
|
|
|
|
|
|
|
cookies.forEach { |
|
|
|
|
|
|
|
CookieStore.replaceCookie(url.toString(), "${it.name}=${it.value}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
override fun loadForRequest(url: HttpUrl): List<Cookie> { |
|
|
|
|
|
|
|
return ArrayList<Cookie>() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager) |
|
|
|
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager) |
|
|
|
.retryOnConnectionFailure(true) |
|
|
|
.retryOnConnectionFailure(true) |
|
|
|
.hostnameVerifier(SSLHelper.unsafeHostnameVerifier) |
|
|
|
.hostnameVerifier(SSLHelper.unsafeHostnameVerifier) |
|
|
@ -60,7 +61,7 @@ val okHttpClient: OkHttpClient by lazy { |
|
|
|
chain.proceed(builder.build()) |
|
|
|
chain.proceed(builder.build()) |
|
|
|
}) |
|
|
|
}) |
|
|
|
if (!AppConfig.isGooglePlay && AppConfig.isCronet && CronetLoader.install()) { |
|
|
|
if (!AppConfig.isGooglePlay && AppConfig.isCronet && CronetLoader.install()) { |
|
|
|
builder.addInterceptor(CronetInterceptor(null)) |
|
|
|
builder.addInterceptor(CronetInterceptor(cookieJar = cookieJar)) |
|
|
|
} |
|
|
|
} |
|
|
|
builder.build() |
|
|
|
builder.build() |
|
|
|
} |
|
|
|
} |
|
|
|