Merge pull request #2067 from 821938089/fix-webdav-with-cronet

修复使用Cronet网络组件后webDav请求中的auth协议头丢失的bug
pull/2072/head
kunfei 2 years ago committed by GitHub
commit 8800334fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      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.help.http.text
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
@ -68,15 +69,18 @@ open class WebDav(val path: String, val authorization: Authorization) {
}.getOrNull() }.getOrNull()
} }
private val webDavClient by lazy { private val webDavClient by lazy {
val clientBuilder = okHttpClient.newBuilder() val authInterceptor = Interceptor { chain ->
clientBuilder.addNetworkInterceptor { chain ->
val request = chain.request() val request = chain.request()
.newBuilder() .newBuilder()
.addHeader(authorization.name, authorization.data) .header(authorization.name, authorization.data)
.build() .build()
chain.proceed(request) chain.proceed(request)
} }
clientBuilder.build() okHttpClient.newBuilder().run {
interceptors().add(0, authInterceptor)
addNetworkInterceptor(authInterceptor)
build()
}
} }
val host: String? get() = url.host val host: String? get() = url.host

Loading…
Cancel
Save