From af769120da9e56933ee81b3af330c7e174deef5c Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 4 May 2021 10:57:15 +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 --- app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt | 6 ++++++ .../java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) 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)