From d7db410c3ed2c5bc558ce1a6441786afee806c6c Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Tue, 12 Jul 2022 22:14:53 +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/lib/webdav/WebDav.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index e63997283..0226c8b00 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -8,6 +8,7 @@ import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.text import io.legado.app.utils.NetworkUtils import io.legado.app.utils.printOnDebug +import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody @@ -68,15 +69,18 @@ open class WebDav(val path: String, val authorization: Authorization) { }.getOrNull() } private val webDavClient by lazy { - val clientBuilder = okHttpClient.newBuilder() - clientBuilder.addNetworkInterceptor { chain -> + val authInterceptor = Interceptor { chain -> val request = chain.request() .newBuilder() - .addHeader(authorization.name, authorization.data) + .header(authorization.name, authorization.data) .build() chain.proceed(request) } - clientBuilder.build() + okHttpClient.newBuilder().run { + interceptors().add(0, authInterceptor) + addNetworkInterceptor(authInterceptor) + build() + } } val host: String? get() = url.host