From 872fa8577d742ff1eaac7583056e5cfb46fb89c8 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 7 May 2022 06:27:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:glide=E9=87=8D=E5=A4=8D=E6=B7=BB=E5=8A=A0ua?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/glide/OkHttpStreamFetcher.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/glide/OkHttpStreamFetcher.kt b/app/src/main/java/io/legado/app/help/glide/OkHttpStreamFetcher.kt index a101d4413..d76bc6f33 100644 --- a/app/src/main/java/io/legado/app/help/glide/OkHttpStreamFetcher.kt +++ b/app/src/main/java/io/legado/app/help/glide/OkHttpStreamFetcher.kt @@ -8,9 +8,11 @@ import com.bumptech.glide.load.data.DataFetcher import com.bumptech.glide.load.model.GlideUrl import com.bumptech.glide.util.ContentLengthInputStream import com.bumptech.glide.util.Preconditions +import io.legado.app.constant.AppConst import io.legado.app.data.appDb import io.legado.app.exception.NoStackTraceException import io.legado.app.help.http.okHttpClient +import io.legado.app.help.http.addHeaders import io.legado.app.utils.isWifiConnect import okhttp3.Call import okhttp3.Request @@ -37,16 +39,19 @@ class OkHttpStreamFetcher(private val url: GlideUrl, private val options: Option return } val requestBuilder: Request.Builder = Request.Builder().url(url.toStringUrl()) + val headerMap = HashMap() + options.get(OkHttpModelLoader.sourceOriginOption)?.let { sourceUrl -> val source = appDb.bookSourceDao.getBookSource(sourceUrl) ?: appDb.rssSourceDao.getByKey(sourceUrl) - source?.getHeaderMap(true)?.forEach { - requestBuilder.addHeader(it.key, it.value) + source?.getHeaderMap(true)?.let { + headerMap.putAll(it) } } for ((key, value) in url.headers.entries) { - requestBuilder.addHeader(key, value) + headerMap.put(key, value) } + requestBuilder.addHeaders(headerMap) val request: Request = requestBuilder.build() this.callback = callback call = okHttpClient.newCall(request)