diff --git a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt index 05e1a6ec3..0c4c186f7 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt @@ -59,7 +59,6 @@ interface BaseSource : JsExtensions { * 解析header规则 */ fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap().apply { - this[AppConst.UA_NAME] = AppConfig.userAgent header?.let { GSON.fromJsonObject>( 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) diff --git a/app/src/main/java/io/legado/app/utils/MapExtensions.kt b/app/src/main/java/io/legado/app/utils/MapExtensions.kt new file mode 100644 index 000000000..520a2b132 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/MapExtensions.kt @@ -0,0 +1,19 @@ +package io.legado.app.utils + +fun HashMap.has(key: String, ignoreCase: Boolean = false): Boolean { + for (item in this) { + if (key.equals(item.key, ignoreCase)) { + return true + } + } + return false +} + +fun HashMap.get(key: String, ignoreCase: Boolean = false): Any? { + for (item in this) { + if (key.equals(item.key, ignoreCase)) { + return item.value + } + } + return null +} \ No newline at end of file