mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
修复因大小写引发的user agent重复的bug
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package io.legado.app.help.http
|
||||
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.http.cronet.CronetInterceptor
|
||||
import io.legado.app.help.http.cronet.CronetLoader
|
||||
@@ -36,12 +37,14 @@ val okHttpClient: OkHttpClient by lazy {
|
||||
.followSslRedirects(true)
|
||||
.addInterceptor(Interceptor { chain ->
|
||||
val request = chain.request()
|
||||
.newBuilder()
|
||||
.addHeader("Keep-Alive", "300")
|
||||
.addHeader("Connection", "Keep-Alive")
|
||||
.addHeader("Cache-Control", "no-cache")
|
||||
.build()
|
||||
chain.proceed(request)
|
||||
val builder = request.newBuilder()
|
||||
if (request.header(AppConst.UA_NAME) == null) {
|
||||
builder.addHeader(AppConst.UA_NAME, AppConfig.userAgent)
|
||||
}
|
||||
builder.addHeader("Keep-Alive", "300")
|
||||
builder.addHeader("Connection", "Keep-Alive")
|
||||
builder.addHeader("Cache-Control", "no-cache")
|
||||
chain.proceed(builder.build())
|
||||
})
|
||||
if (!AppConfig.isGooglePlay && AppConfig.isCronet && CronetLoader.install()) {
|
||||
builder.addInterceptor(CronetInterceptor(null))
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package io.legado.app.help.http
|
||||
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.utils.EncodingDetect
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.Utf8BomUtils
|
||||
@@ -25,7 +23,6 @@ suspend fun OkHttpClient.newCallResponse(
|
||||
): Response {
|
||||
return withContext(IO) {
|
||||
val requestBuilder = Request.Builder()
|
||||
requestBuilder.header(AppConst.UA_NAME, AppConfig.userAgent)
|
||||
requestBuilder.apply(builder)
|
||||
var response: Response? = null
|
||||
for (i in 0..retry) {
|
||||
@@ -94,10 +91,6 @@ fun ResponseBody.text(encode: String? = null): String {
|
||||
|
||||
fun Request.Builder.addHeaders(headers: Map<String, String>) {
|
||||
headers.forEach {
|
||||
if (it.key == AppConst.UA_NAME) {
|
||||
//防止userAgent重复
|
||||
removeHeader(AppConst.UA_NAME)
|
||||
}
|
||||
addHeader(it.key, it.value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user