pull/977/head
gedoor 4 years ago
parent 3f4bf36ba2
commit b86339364d
  1. 4
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  2. 2
      app/src/main/java/io/legado/app/help/http/OkHttpExtensions.kt
  3. 12
      app/src/main/java/io/legado/app/help/http/RetryInterceptor.kt
  4. 10
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt

@ -36,7 +36,7 @@ object HttpHelper {
.connectionSpecs(specs) .connectionSpecs(specs)
.followRedirects(true) .followRedirects(true)
.followSslRedirects(true) .followSslRedirects(true)
.addInterceptor(getHeaderInterceptor()) .addInterceptor(headerInterceptor())
builder.build() builder.build()
} }
@ -85,7 +85,7 @@ object HttpHelper {
return client return client
} }
private fun getHeaderInterceptor(): Interceptor { private fun headerInterceptor(): Interceptor {
return Interceptor { chain -> return Interceptor { chain ->
val request = chain.request() val request = chain.request()
.newBuilder() .newBuilder()

@ -1,4 +1,4 @@
package io.legado.app.utils package io.legado.app.help.http
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call import okhttp3.Call

@ -0,0 +1,12 @@
package io.legado.app.help.http
import okhttp3.Interceptor
import okhttp3.Response
class RetryInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
TODO("Not yet implemented")
}
}

@ -1,14 +1,12 @@
package io.legado.app.lib.webdav package io.legado.app.lib.webdav
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.utils.await import io.legado.app.help.http.await
import okhttp3.* import okhttp3.*
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
import org.jsoup.Jsoup import org.jsoup.Jsoup
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toInputStream
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
@ -238,9 +236,11 @@ class WebDav(urlStr: String) {
val url = httpUrl val url = httpUrl
val auth = HttpAuth.auth val auth = HttpAuth.auth
if (url != null && auth != null) { if (url != null && auth != null) {
return RxHttp.get(url) val requestBuilder = Request.Builder()
.url(url)
.addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) .addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
.toInputStream().await() return HttpHelper.client.newCall(request = requestBuilder.build()).await()
.body?.byteStream()
} }
return null return null
} }

Loading…
Cancel
Save