优化
This commit is contained in:
@@ -59,7 +59,6 @@ interface BaseSource : JsExtensions {
|
|||||||
* 解析header规则
|
* 解析header规则
|
||||||
*/
|
*/
|
||||||
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
|
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
|
||||||
this[AppConst.UA_NAME] = AppConfig.userAgent
|
|
||||||
header?.let {
|
header?.let {
|
||||||
GSON.fromJsonObject<Map<String, String>>(
|
GSON.fromJsonObject<Map<String, String>>(
|
||||||
when {
|
when {
|
||||||
@@ -73,6 +72,9 @@ interface BaseSource : JsExtensions {
|
|||||||
putAll(map)
|
putAll(map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!has(AppConst.UA_NAME, true)) {
|
||||||
|
put(AppConst.UA_NAME, AppConfig.userAgent)
|
||||||
|
}
|
||||||
if (hasLoginHeader) {
|
if (hasLoginHeader) {
|
||||||
getLoginHeaderMap()?.let {
|
getLoginHeaderMap()?.let {
|
||||||
putAll(it)
|
putAll(it)
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
fun HashMap<String, *>.has(key: String, ignoreCase: Boolean = false): Boolean {
|
||||||
|
for (item in this) {
|
||||||
|
if (key.equals(item.key, ignoreCase)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun HashMap<String, *>.get(key: String, ignoreCase: Boolean = false): Any? {
|
||||||
|
for (item in this) {
|
||||||
|
if (key.equals(item.key, ignoreCase)) {
|
||||||
|
return item.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user