优化
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package io.legado.app.help.http
|
package io.legado.app.help.http
|
||||||
|
|
||||||
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.help.CacheManager
|
import io.legado.app.help.CacheManager
|
||||||
import io.legado.app.utils.NetworkUtils
|
import io.legado.app.utils.NetworkUtils
|
||||||
@@ -49,15 +50,24 @@ object CookieManager {
|
|||||||
* 加载Cookies到请求中
|
* 加载Cookies到请求中
|
||||||
*/
|
*/
|
||||||
fun loadRequest(request: Request): Request {
|
fun loadRequest(request: Request): Request {
|
||||||
val domain = NetworkUtils.getSubDomain(request.url.toString())
|
val url = request.url.toString()
|
||||||
|
val domain = NetworkUtils.getSubDomain(url)
|
||||||
|
|
||||||
val cookie = CookieStore.getCookie(domain)
|
val cookie = CookieStore.getCookie(domain)
|
||||||
val requestCookie = request.header("Cookie")
|
val requestCookie = request.header("Cookie")
|
||||||
|
|
||||||
mergeCookies(cookie, requestCookie)?.let {
|
mergeCookies(cookie, requestCookie)?.let { cookie ->
|
||||||
return request.newBuilder()
|
kotlin.runCatching {
|
||||||
.header("Cookie", it)
|
return request.newBuilder()
|
||||||
.build()
|
.header("Cookie", cookie)
|
||||||
|
.build()
|
||||||
|
}.onFailure {
|
||||||
|
CookieStore.removeCookie(url)
|
||||||
|
AppLog.put(
|
||||||
|
"设置cookie出错,已清除cookie $domain cookie:$cookie\n${it.localizedMessage}",
|
||||||
|
it
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user