pull/1517/head
gedoor 3 years ago
parent 3bb8c0c3ab
commit 4fd13433ed
  1. 13
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt

@ -141,11 +141,16 @@ object NetworkUtils {
fun getBaseUrl(url: String?): String? {
url ?: return null
if (url.startsWith("http://", true)
|| url.startsWith("https://", true)
) {
val index = url.indexOf("/", 9)
return if (index == -1) {
url
} else url.substring(0, index)
}
return null
}
/**
* 获取二级域名供cookie保存和读取
@ -156,10 +161,7 @@ object NetworkUtils {
*/
fun getSubDomain(url: String): String {
val baseUrl = getBaseUrl(url) ?: return url
return if (url.startsWith("http://", true)
|| url.startsWith("https://", true)
) {
kotlin.runCatching {
return kotlin.runCatching {
val mURL = URL(baseUrl)
val host: String = mURL.host
//判断是否为ip
@ -167,9 +169,6 @@ object NetworkUtils {
//PublicSuffixDatabase处理域名
PublicSuffixDatabase.get().getEffectiveTldPlusOne(host) ?: baseUrl
}.getOrDefault(baseUrl)
} else {
baseUrl
}
}
/**

Loading…
Cancel
Save