Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit c2f7426

Browse files
authored
Merge pull request #515 from owncloud/feature/handle_425_response
Handle 425 TOO EARLY propfind responses
2 parents 376d52a + 1e9d8ce commit c2f7426

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public class HttpConstants {
184184
public static final int HTTP_LOCKED = 423;
185185
// 424 Failed Dependency (WebDAV - RFC 2518)
186186
public static final int HTTP_FAILED_DEPENDENCY = 424;
187+
public static final int HTTP_TOO_EARLY = 425;
187188

188189
/**
189190
* 5xx Client Error

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ public RemoteOperationResult(HttpBaseMethod httpMethod) throws IOException {
237237
httpMethod.getResponseBodyAsString(),
238238
ResultCode.SPECIFIC_METHOD_NOT_ALLOWED
239239
);
240+
break;
241+
case HttpConstants.HTTP_TOO_EARLY:
242+
mCode = ResultCode.TOO_EARLY;
243+
break;
240244
default:
241245
break;
242246
}
@@ -583,6 +587,7 @@ public enum ResultCode {
583587
SPECIFIC_SERVICE_UNAVAILABLE,
584588
SPECIFIC_UNSUPPORTED_MEDIA_TYPE,
585589
SPECIFIC_METHOD_NOT_ALLOWED,
586-
SPECIFIC_BAD_REQUEST
590+
SPECIFIC_BAD_REQUEST,
591+
TOO_EARLY,
587592
}
588593
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public RemoteFile(String path) {
120120

121121
public RemoteFile(final Response davResource, String userId) {
122122
this(RemoteFileUtil.Companion.getRemotePathFromUrl(davResource.getHref(), userId));
123-
final List<Property> properties = davResource.getProperties();
123+
final List<Property> properties = RemoteFileUtil.Companion.getProperties(davResource);
124124

125125
for (Property property : properties) {
126126
if (property instanceof CreationDate) {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
package com.owncloud.android.lib.resources.files
2525

2626
import android.net.Uri
27+
import at.bitfire.dav4jvm.PropStat
28+
import at.bitfire.dav4jvm.Property
29+
import at.bitfire.dav4jvm.Response
2730
import com.owncloud.android.lib.common.OwnCloudClient
31+
import com.owncloud.android.lib.common.http.HttpConstants
2832
import okhttp3.HttpUrl
2933

3034
class RemoteFileUtil {
@@ -45,5 +49,14 @@ class RemoteFileUtil {
4549
val pathToOc = absoluteDavPath.split(davFilesPath)[0]
4650
return absoluteDavPath.replace(pathToOc + davFilesPath, "")
4751
}
52+
53+
fun getProperties(response: Response): List<Property> {
54+
return if (response.isSuccess())
55+
response.propstat.filter { propStat -> propStat.isSuccessOrPostProcessing() }.map { it.properties }.flatten()
56+
else
57+
emptyList()
58+
}
59+
60+
private fun PropStat.isSuccessOrPostProcessing() = (status.code / 100 == 2 || status.code == HttpConstants.HTTP_TOO_EARLY)
4861
}
4962
}

0 commit comments

Comments
 (0)