From 11f694662010d72e999f4feb302b47620bc97d66 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jun 2022 17:39:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BaseSource.kt | 4 +++- .../java/io/legado/app/utils/MapExtensions.kt | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/legado/app/utils/MapExtensions.kt 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