From b083debac9a73f306c85e261ad26771c993543b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garc=C3=ADa=20de=20Prada?= Date: Tue, 11 Oct 2022 17:32:19 +0200 Subject: [PATCH 1/2] Handle 425 TOO EARLY propfind responses --- .../android/lib/common/http/HttpConstants.java | 1 + .../android/lib/resources/files/RemoteFile.java | 2 +- .../android/lib/resources/files/RemoteFileUtil.kt | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java index 091643ab..8978a556 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java @@ -184,6 +184,7 @@ public class HttpConstants { public static final int HTTP_LOCKED = 423; // 424 Failed Dependency (WebDAV - RFC 2518) public static final int HTTP_FAILED_DEPENDENCY = 424; + public static final int HTTP_TOO_EARLY = 425; /** * 5xx Client Error diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java index 84a48bcd..8d243d14 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java @@ -120,7 +120,7 @@ public class RemoteFile implements Parcelable, Serializable { public RemoteFile(final Response davResource, String userId) { this(RemoteFileUtil.Companion.getRemotePathFromUrl(davResource.getHref(), userId)); - final List properties = davResource.getProperties(); + final List properties = RemoteFileUtil.Companion.getProperties(davResource); for (Property property : properties) { if (property instanceof CreationDate) { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt index 30550e70..66609bd1 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt @@ -24,7 +24,11 @@ package com.owncloud.android.lib.resources.files import android.net.Uri +import at.bitfire.dav4jvm.PropStat +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.Response import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.http.HttpConstants import okhttp3.HttpUrl class RemoteFileUtil { @@ -45,5 +49,14 @@ class RemoteFileUtil { val pathToOc = absoluteDavPath.split(davFilesPath)[0] return absoluteDavPath.replace(pathToOc + davFilesPath, "") } + + fun getProperties(response: Response): List { + return if (response.isSuccess()) + response.propstat.filter { propStat -> propStat.isSuccessOrPostProcessing() }.map { it.properties }.flatten() + else + emptyList() + } + + private fun PropStat.isSuccessOrPostProcessing() = (status.code / 100 == 2 || status.code == HttpConstants.HTTP_TOO_EARLY) } } From 1e9d8cef42132c24fca2623660f04f1f5310add0 Mon Sep 17 00:00:00 2001 From: Juan Carlos Garrote Date: Fri, 28 Oct 2022 10:05:09 +0200 Subject: [PATCH 2/2] Handle 425 when trying to open in web --- .../lib/common/operations/RemoteOperationResult.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 7430771d..5d849b08 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -237,6 +237,10 @@ public class RemoteOperationResult httpMethod.getResponseBodyAsString(), ResultCode.SPECIFIC_METHOD_NOT_ALLOWED ); + break; + case HttpConstants.HTTP_TOO_EARLY: + mCode = ResultCode.TOO_EARLY; + break; default: break; } @@ -583,6 +587,7 @@ public class RemoteOperationResult SPECIFIC_SERVICE_UNAVAILABLE, SPECIFIC_UNSUPPORTED_MEDIA_TYPE, SPECIFIC_METHOD_NOT_ALLOWED, - SPECIFIC_BAD_REQUEST + SPECIFIC_BAD_REQUEST, + TOO_EARLY, } }