mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
fix(getSubDomain):二级域名带http/https
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
|
||||
* 修复解码正文图片报错,添加解码日志
|
||||
* js文档:java.toast java.longToast
|
||||
* cookie保存策略更改,若登录失效请重新登录
|
||||
|
||||
**2022/04/12**
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ import io.legado.app.utils.NetworkUtils
|
||||
|
||||
object CookieStore : CookieManager {
|
||||
|
||||
/**
|
||||
*保存cookie到数据库,会自动识别url的二级域名
|
||||
*/
|
||||
override fun setCookie(url: String, cookie: String?) {
|
||||
val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "")
|
||||
appDb.cookieDao.insert(cookieBean)
|
||||
@@ -30,6 +33,9 @@ object CookieStore : CookieManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*获取url所属的二级域名的cookie
|
||||
*/
|
||||
override fun getCookie(url: String): String {
|
||||
val cookieBean = appDb.cookieDao.get(NetworkUtils.getSubDomain(url))
|
||||
return cookieBean?.cookie ?: ""
|
||||
|
||||
@@ -130,6 +130,8 @@ object NetworkUtils {
|
||||
*/
|
||||
fun getAbsoluteURL(baseURL: URL?, relativePath: String): String {
|
||||
if (baseURL == null) return relativePath
|
||||
if (relativePath.isAbsUrl()) return relativePath
|
||||
if (relativePath.matches(AppPattern.dataUriRegex)) return relativePath
|
||||
if (relativePath.startsWith("javascript")) return ""
|
||||
var relativeUrl = relativePath
|
||||
try {
|
||||
@@ -156,7 +158,7 @@ object NetworkUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取域名,供cookie保存和读取
|
||||
* 获取域名,供cookie保存和读取,处理失败返回传入的url
|
||||
* http://1.2.3.4 => 1.2.3.4
|
||||
* https://www.example.com => example.com
|
||||
* http://www.biquge.com.cn => biquge.com.cn
|
||||
@@ -167,10 +169,11 @@ object NetworkUtils {
|
||||
return kotlin.runCatching {
|
||||
val mURL = URL(baseUrl)
|
||||
val host: String = mURL.host
|
||||
//mURL.scheme https/http
|
||||
//判断是否为ip
|
||||
if (isIPAddress(host)) return baseUrl
|
||||
if (isIPAddress(host)) return host
|
||||
//PublicSuffixDatabase处理域名
|
||||
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl
|
||||
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: host
|
||||
}.getOrDefault(baseUrl)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user