优化
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user