|
|
@ -74,6 +74,7 @@ class AnalyzeUrl( |
|
|
|
private var useWebView: Boolean = false |
|
|
|
private var useWebView: Boolean = false |
|
|
|
private var webJs: String? = null |
|
|
|
private var webJs: String? = null |
|
|
|
private val enabledCookieJar = source?.enabledCookieJar ?: false |
|
|
|
private val enabledCookieJar = source?.enabledCookieJar ?: false |
|
|
|
|
|
|
|
private val domain: String |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
val urlMatcher = paramPattern.matcher(baseUrl) |
|
|
|
val urlMatcher = paramPattern.matcher(baseUrl) |
|
|
@ -86,6 +87,7 @@ class AnalyzeUrl( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
initUrl() |
|
|
|
initUrl() |
|
|
|
|
|
|
|
domain = NetworkUtils.getSubDomain(source?.getKey() ?: url) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -368,7 +370,7 @@ class AnalyzeUrl( |
|
|
|
} |
|
|
|
} |
|
|
|
val concurrentRecord = fetchStart() |
|
|
|
val concurrentRecord = fetchStart() |
|
|
|
try { |
|
|
|
try { |
|
|
|
setCookie(source?.getKey()) |
|
|
|
setCookie() |
|
|
|
val strResponse: StrResponse |
|
|
|
val strResponse: StrResponse |
|
|
|
if (this.useWebView && useWebView) { |
|
|
|
if (this.useWebView && useWebView) { |
|
|
|
strResponse = when (method) { |
|
|
|
strResponse = when (method) { |
|
|
@ -422,6 +424,7 @@ class AnalyzeUrl( |
|
|
|
} |
|
|
|
} |
|
|
|
return strResponse |
|
|
|
return strResponse |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
|
|
|
|
saveCookie() |
|
|
|
fetchEnd(concurrentRecord) |
|
|
|
fetchEnd(concurrentRecord) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -463,7 +466,7 @@ class AnalyzeUrl( |
|
|
|
suspend fun getResponseAwait(): Response { |
|
|
|
suspend fun getResponseAwait(): Response { |
|
|
|
val concurrentRecord = fetchStart() |
|
|
|
val concurrentRecord = fetchStart() |
|
|
|
try { |
|
|
|
try { |
|
|
|
setCookie(source?.getKey()) |
|
|
|
setCookie() |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
val response = getProxyClient(proxy).newCallResponse(retry) { |
|
|
|
val response = getProxyClient(proxy).newCallResponse(retry) { |
|
|
|
addHeaders(headerMap) |
|
|
|
addHeaders(headerMap) |
|
|
@ -486,6 +489,7 @@ class AnalyzeUrl( |
|
|
|
} |
|
|
|
} |
|
|
|
return response |
|
|
|
return response |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
|
|
|
|
saveCookie() |
|
|
|
fetchEnd(concurrentRecord) |
|
|
|
fetchEnd(concurrentRecord) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -569,21 +573,19 @@ class AnalyzeUrl( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*设置cookie 优先级 |
|
|
|
* 设置cookie 优先级 |
|
|
|
* urlOption临时cookie > 数据库cookie = okhttp CookieJar保存在内存中的cookie |
|
|
|
* urlOption临时cookie > 数据库cookie = okhttp CookieJar保存在内存中的cookie |
|
|
|
*@param tag 书源url 缺省为传入的url |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun setCookie(tag: String?) { |
|
|
|
private fun setCookie() { |
|
|
|
val domain = NetworkUtils.getSubDomain(tag ?: url) |
|
|
|
val cookie = kotlin.run { |
|
|
|
//书源启用保存cookie时 添加内存中的cookie到数据库 |
|
|
|
if (enabledCookieJar) { |
|
|
|
if (enabledCookieJar) { |
|
|
|
val key = "${domain}_cookieJar" |
|
|
|
val key = "${domain}_cookieJar" |
|
|
|
CacheManager.getFromMemory(key)?.let { |
|
|
|
CacheManager.getFromMemory(key)?.let { |
|
|
|
return@run it |
|
|
|
CookieStore.replaceCookie(domain, it) |
|
|
|
} |
|
|
|
CacheManager.deleteMemory(key) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
CookieStore.getCookie(domain) |
|
|
|
} |
|
|
|
} |
|
|
|
val cookie = CookieStore.getCookie(domain) |
|
|
|
|
|
|
|
if (cookie.isNotEmpty()) { |
|
|
|
if (cookie.isNotEmpty()) { |
|
|
|
val cookieMap = CookieStore.cookieToMap(cookie) |
|
|
|
val cookieMap = CookieStore.cookieToMap(cookie) |
|
|
|
val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "") |
|
|
|
val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "") |
|
|
@ -594,11 +596,26 @@ class AnalyzeUrl( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 保存cookie |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun saveCookie() { |
|
|
|
|
|
|
|
//书源启用保存cookie时 添加内存中的cookie到数据库 |
|
|
|
|
|
|
|
if (enabledCookieJar) { |
|
|
|
|
|
|
|
val key = "${domain}_cookieJar" |
|
|
|
|
|
|
|
CacheManager.getFromMemory(key)?.let { |
|
|
|
|
|
|
|
CookieStore.replaceCookie(domain, it) |
|
|
|
|
|
|
|
CacheManager.deleteMemory(key) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*获取处理过阅读定义的urlOption和cookie的GlideUrl |
|
|
|
*获取处理过阅读定义的urlOption和cookie的GlideUrl |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun getGlideUrl(): GlideUrl { |
|
|
|
fun getGlideUrl(): GlideUrl { |
|
|
|
setCookie(source?.getKey()) |
|
|
|
setCookie() |
|
|
|
return GlideUrl(url, GlideHeaders(headerMap)) |
|
|
|
return GlideUrl(url, GlideHeaders(headerMap)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|