From 676e8a2a58e5e685e473cc6276892896915541f4 Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Tue, 12 Jul 2022 11:06:22 +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 --- .../java/io/legado/app/lib/webdav/WebDav.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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 d15eef51c..e63997283 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 @@ -46,6 +46,15 @@ open class WebDav(val path: String, val authorization: Authorization) { %s """ + + @Language("xml") + private const val EXISTS = + """ + + + + + """ } private val url: URL = URL(path) @@ -189,14 +198,12 @@ open class WebDav(val path: String, val authorization: Authorization) { */ suspend fun exists(): Boolean { val url = httpUrl ?: return false - //当使用自建的WebDav服务时,在末尾有否 ”/“ 会影响请求的成功与否 - //使用坚果云的WebDav则不会,这里做一个简单的替换来解决这个问题 - val testUrl = url.removeSuffix("/") + "/" return kotlin.runCatching { return webDavClient.newCallResponse { - url(testUrl) - head() - //某些自建的WebDav服务,请求数据时返回码不一定为 200,如 caddy 为207,所以改为在200-300区间 + url(url) + addHeader("Depth", "0") + val requestBody = EXISTS.toRequestBody("application/xml".toMediaType()) + method("PROPFIND", requestBody) }.isSuccessful }.getOrDefault(false) }