Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jun 26, 2023
1 parent 1ac5dfd commit 0bffbb6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/src/main/java/io/legado/app/help/http/CookieManager.kt
@@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0bffbb6

Please sign in to comment.