From b86339364d6f2e0a487e3f93fea5c27b5377ef91 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 2 May 2021 22:31:14 +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 --- .../main/java/io/legado/app/help/http/HttpHelper.kt | 4 ++-- .../app/{utils => help/http}/OkHttpExtensions.kt | 2 +- .../java/io/legado/app/help/http/RetryInterceptor.kt | 12 ++++++++++++ app/src/main/java/io/legado/app/lib/webdav/WebDav.kt | 10 +++++----- 4 files changed, 20 insertions(+), 8 deletions(-) rename app/src/main/java/io/legado/app/{utils => help/http}/OkHttpExtensions.kt (94%) create mode 100644 app/src/main/java/io/legado/app/help/http/RetryInterceptor.kt diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 6a9f7f8b9..a6331d8a6 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -36,7 +36,7 @@ object HttpHelper { .connectionSpecs(specs) .followRedirects(true) .followSslRedirects(true) - .addInterceptor(getHeaderInterceptor()) + .addInterceptor(headerInterceptor()) builder.build() } @@ -85,7 +85,7 @@ object HttpHelper { return client } - private fun getHeaderInterceptor(): Interceptor { + private fun headerInterceptor(): Interceptor { return Interceptor { chain -> val request = chain.request() .newBuilder() diff --git a/app/src/main/java/io/legado/app/utils/OkHttpExtensions.kt b/app/src/main/java/io/legado/app/help/http/OkHttpExtensions.kt similarity index 94% rename from app/src/main/java/io/legado/app/utils/OkHttpExtensions.kt rename to app/src/main/java/io/legado/app/help/http/OkHttpExtensions.kt index b21bcc8e4..e17fa35c4 100644 --- a/app/src/main/java/io/legado/app/utils/OkHttpExtensions.kt +++ b/app/src/main/java/io/legado/app/help/http/OkHttpExtensions.kt @@ -1,4 +1,4 @@ -package io.legado.app.utils +package io.legado.app.help.http import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.Call diff --git a/app/src/main/java/io/legado/app/help/http/RetryInterceptor.kt b/app/src/main/java/io/legado/app/help/http/RetryInterceptor.kt new file mode 100644 index 000000000..00c4a0881 --- /dev/null +++ b/app/src/main/java/io/legado/app/help/http/RetryInterceptor.kt @@ -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") + } + +} \ No newline at end of file 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 1570bc793..51c8e93ae 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 @@ -1,14 +1,12 @@ package io.legado.app.lib.webdav import io.legado.app.help.http.HttpHelper -import io.legado.app.utils.await +import io.legado.app.help.http.await import okhttp3.* import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import org.jsoup.Jsoup -import rxhttp.wrapper.param.RxHttp -import rxhttp.wrapper.param.toInputStream import java.io.File import java.io.IOException import java.io.InputStream @@ -238,9 +236,11 @@ class WebDav(urlStr: String) { val url = httpUrl val auth = HttpAuth.auth if (url != null && auth != null) { - return RxHttp.get(url) + val requestBuilder = Request.Builder() + .url(url) .addHeader("Authorization", Credentials.basic(auth.user, auth.pass)) - .toInputStream().await() + return HttpHelper.client.newCall(request = requestBuilder.build()).await() + .body?.byteStream() } return null }