pull/1999/head
kunfei 2 years ago
parent e5346b3862
commit 11f6946620
  1. 4
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  2. 19
      app/src/main/java/io/legado/app/utils/MapExtensions.kt

@ -59,7 +59,6 @@ interface BaseSource : JsExtensions {
* 解析header规则
*/
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
this[AppConst.UA_NAME] = AppConfig.userAgent
header?.let {
GSON.fromJsonObject<Map<String, String>>(
when {
@ -73,6 +72,9 @@ interface BaseSource : JsExtensions {
putAll(map)
}
}
if (!has(AppConst.UA_NAME, true)) {
put(AppConst.UA_NAME, AppConfig.userAgent)
}
if (hasLoginHeader) {
getLoginHeaderMap()?.let {
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
}
Loading…
Cancel
Save