diff --git a/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt b/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt index d958fc5a2..3b15acf5d 100644 --- a/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt +++ b/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt @@ -82,6 +82,12 @@ fun ResponseBody.text(encode: String? = null): String { return String(responseBytes, Charset.forName(charsetName)) } +fun Request.Builder.addHeaders(headers: Map) { + headers.forEach { + addHeader(it.key, it.value) + } +} + fun Request.Builder.get(url: String, queryMap: Map, encoded: Boolean = false) { val httpBuilder = url.toHttpUrl().newBuilder() queryMap.forEach { diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 088090555..73e90e782 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -308,9 +308,7 @@ class AnalyzeUrl( } return getProxyClient(proxy).newCallStrResponse(retry) { removeHeader(UA_NAME) - headerMap.forEach { - addHeader(it.key, it.value) - } + addHeaders(headerMap) when (method) { RequestMethod.POST -> { url(url) @@ -330,9 +328,7 @@ class AnalyzeUrl( @Suppress("BlockingMethodInNonBlockingContext") return getProxyClient(proxy).newCall(retry) { removeHeader(UA_NAME) - headerMap.forEach { - addHeader(it.key, it.value) - } + addHeaders(headerMap) when (method) { RequestMethod.POST -> { url(url)