mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
1ac5dfd37f
commit
0bffbb6c9f
@ -1,5 +1,6 @@
|
||||
package io.legado.app.help.http
|
||||
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.utils.NetworkUtils
|
||||
@ -49,15 +50,24 @@ object CookieManager {
|
||||
* 加载Cookies到请求中
|
||||
*/
|
||||
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 requestCookie = request.header("Cookie")
|
||||
|
||||
mergeCookies(cookie, requestCookie)?.let {
|
||||
return request.newBuilder()
|
||||
.header("Cookie", it)
|
||||
.build()
|
||||
mergeCookies(cookie, requestCookie)?.let { cookie ->
|
||||
kotlin.runCatching {
|
||||
return request.newBuilder()
|
||||
.header("Cookie", cookie)
|
||||
.build()
|
||||
}.onFailure {
|
||||
CookieStore.removeCookie(url)
|
||||
AppLog.put(
|
||||
"设置cookie出错,已清除cookie $domain cookie:$cookie\n${it.localizedMessage}",
|
||||
it
|
||||
)
|
||||
}
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user