diff --git a/src/main/java/com/nextcloud/common/NextcloudClient.kt b/src/main/java/com/nextcloud/common/NextcloudClient.kt index 1e98726a7..00f0d58fe 100644 --- a/src/main/java/com/nextcloud/common/NextcloudClient.kt +++ b/src/main/java/com/nextcloud/common/NextcloudClient.kt @@ -113,7 +113,8 @@ class NextcloudClient(var baseUri: Uri, while (redirectionsCount < OwnCloudClient.MAX_REDIRECTIONS_COUNT && (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || - status == HttpStatus.SC_TEMPORARY_REDIRECT)) { + status == HttpStatus.SC_TEMPORARY_REDIRECT || + status == /* Permanent Redirect */ 308)) { var location = method.getResponseHeader("Location") if (location == null) { location = method.getResponseHeader("location") @@ -132,7 +133,11 @@ class NextcloudClient(var baseUri: Uri, } if (destination != null) { - val suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_4_0) + var suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_4_0) + if (suffixIndex == -1) { + suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_9_0) + } + check (suffixIndex != -1) { "Failed to find webdav substring in $location" } val redirectionBase = location.substring(0, suffixIndex) val destinationStr = destination val destinationPath = destinationStr.substring(baseUri.toString().length) diff --git a/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java index 8b5732d11..96f7cd306 100644 --- a/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java @@ -242,7 +242,8 @@ public RedirectionPath followRedirection(HttpMethod method) throws IOException { while (redirectionsCount < MAX_REDIRECTIONS_COUNT && ( status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || - status == HttpStatus.SC_TEMPORARY_REDIRECT) + status == HttpStatus.SC_TEMPORARY_REDIRECT || + status == /* Permanent Redirect */ 308) ) { Header location = method.getResponseHeader("Location"); @@ -268,6 +269,12 @@ public RedirectionPath followRedirection(HttpMethod method) throws IOException { } if (destination != null) { int suffixIndex = locationStr.lastIndexOf(AccountUtils.WEBDAV_PATH_4_0); + if (suffixIndex == -1) { + suffixIndex = locationStr.lastIndexOf(AccountUtils.WEBDAV_PATH_9_0); + } + if (suffixIndex == -1) { + throw new IllegalStateException("Failed to find webdav substring in " + locationStr); + } String redirectionBase = locationStr.substring(0, suffixIndex); String destinationStr = destination.getValue(); diff --git a/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java b/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java index 4ba9bc725..7ad3f0ca9 100644 --- a/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java +++ b/src/main/java/com/owncloud/android/lib/resources/files/ChunkedFileUploadRemoteOperation.java @@ -309,6 +309,7 @@ private RemoteOperationResult uploadChunk(OwnCloudClient client, String uploadFo private PutMethod createPutMethod(String uriPrefix) { putMethod = new PutMethod(uriPrefix); putMethod.setRequestEntity(entity); + putMethod.setUseExpectHeader(true); if (cancellationRequested.get()) { putMethod.abort(); // next method will throw an exception }