diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index f97588a87..a565560b7 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -63,7 +63,7 @@ object CookieStore : CookiePersistor { return cookieMap } - private fun mapToCookie(cookieMap: Map?): String? { + fun mapToCookie(cookieMap: Map?): String? { if (cookieMap == null || cookieMap.isEmpty()) { return null } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 160c0debf..a7eb08968 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -281,7 +281,13 @@ class AnalyzeUrl( fun getResponse(tag: String): Call { val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { - headerMap["Cookie"] += ";${cookie}" + val cookieMap = CookieStore.cookieToMap(cookie) + val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + cookieMap.putAll(customCookieMap) + val newCookie = CookieStore.mapToCookie(cookieMap) + newCookie?.let { + headerMap.put("Cookie", it) + } } return when { method == RequestMethod.POST -> { @@ -312,6 +318,16 @@ class AnalyzeUrl( if (type != null) { return Res(url, StringUtils.byteToHexString(getResponseBytes(tag))) } + val cookie = CookieStore.getCookie(tag) + if (cookie.isNotEmpty()) { + val cookieMap = CookieStore.cookieToMap(cookie) + val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + cookieMap.putAll(customCookieMap) + val newCookie = CookieStore.mapToCookie(cookieMap) + newCookie?.let { + headerMap.put("Cookie", it) + } + } if (useWebView) { val params = AjaxWebView.AjaxParams(url) params.headerMap = headerMap @@ -322,10 +338,6 @@ class AnalyzeUrl( params.tag = tag return HttpHelper.ajax(params) } - val cookie = CookieStore.getCookie(tag) - if (cookie.isNotEmpty()) { - headerMap["Cookie"] += ";${cookie}" - } val res = when { method == RequestMethod.POST -> { if (fieldMap.isNotEmpty()) { @@ -356,7 +368,13 @@ class AnalyzeUrl( if (tag != null) { val cookie = CookieStore.getCookie(tag) if (cookie.isNotEmpty()) { - headerMap["Cookie"] += ";${cookie}" + val cookieMap = CookieStore.cookieToMap(cookie) + val customCookieMap = CookieStore.cookieToMap(headerMap.get("Cookie") ?: "") + cookieMap.putAll(customCookieMap) + val newCookie = CookieStore.mapToCookie(cookieMap) + newCookie?.let { + headerMap.put("Cookie", it) + } } } val response = when {