pull/977/head
gedoor 4 years ago
parent d9bcb7506a
commit 9e029a6823
  1. 9
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  2. 10
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt

@ -1,12 +1,19 @@
package io.legado.app.help.http
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Request
import okhttp3.Response
import kotlin.coroutines.resume
@Suppress("unused")
object HttpHelper {
suspend fun newCall(builder: Request.Builder.() -> Unit, proxy: String? = null): Response {
val client = OkHttpHelper.getProxyClient(proxy)
val requestBuilder = Request.Builder().apply(builder)
return client.newCall(requestBuilder.build()).await()
}
suspend fun ajax(params: AjaxWebView.AjaxParams): StrResponse =
suspendCancellableCoroutine { block ->
val webView = AjaxWebView()

@ -1,5 +1,6 @@
package io.legado.app.lib.webdav
import io.legado.app.help.http.HttpHelper
import io.legado.app.help.http.await
import io.legado.app.help.http.okHttpClient
import okhttp3.*
@ -236,11 +237,10 @@ class WebDav(urlStr: String) {
val url = httpUrl
val auth = HttpAuth.auth
if (url != null && auth != null) {
val requestBuilder = Request.Builder()
.url(url)
.addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
return okHttpClient.newCall(request = requestBuilder.build()).await()
.body?.byteStream()
return HttpHelper.newCall({
url(url)
addHeader("Authorization", Credentials.basic(auth.user, auth.pass))
}).body?.byteStream()
}
return null
}

Loading…
Cancel
Save