pull/2067/head
821938089 2 years ago
parent f43a59d3da
commit d7db410c3e
  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.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

Loading…
Cancel
Save