diff --git a/dav4android b/dav4android index b20c44c6..1108048f 160000 --- a/dav4android +++ b/dav4android @@ -1 +1 @@ -Subproject commit b20c44c63f45355599d4bfaf00042964b9e6cafa +Subproject commit 1108048f1a2ff12103cdf6a95307a314d621c088 diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index 12bf18a9..28a90c68 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -46,6 +46,7 @@ import java.io.InputStream; import java.util.List; import at.bitfire.dav4android.exception.HttpException; +import at.bitfire.dav4android.exception.RedirectException; import okhttp3.Cookie; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -131,16 +132,21 @@ public class OwnCloudClient extends HttpClient { boolean repeatWithFreshCredentials; int repeatCounter = 0; - int status; + int status = -1; do { try { status = method.execute(); - } catch (HttpException e) { - if(e.getMessage().contains(Integer.toString(HttpConstants.HTTP_MOVED_TEMPORARILY))) { + checkFirstRedirection(method); + if(mFollowRedirects) { + status = followRedirection(method).getLastStatus(); + } + } catch (RedirectException e) { + // redirect must be handled twice. Once for dav4droid and once okhttp redirect errors + status = e.getStatus(); + mRedirectedLocation = e.getRedirectLocation(); + if(mFollowRedirects) { status = followRedirection(method).getLastStatus(); - } else { - throw e; } } @@ -153,6 +159,14 @@ public class OwnCloudClient extends HttpClient { return status; } + private void checkFirstRedirection(HttpBaseMethod method) { + + final String location = method.getResponseHeader("location"); + if(location != null && !location.isEmpty()) { + mRedirectedLocation = location; + } + } + private int executeRedirectedHttpMethod (HttpBaseMethod method) throws Exception { boolean repeatWithFreshCredentials; int repeatCounter = 0; diff --git a/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java b/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java index 7c5c0332..59802714 100644 --- a/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java +++ b/src/com/owncloud/android/lib/common/http/methods/webdav/DavMethod.java @@ -47,6 +47,7 @@ public abstract class DavMethod extends HttpBaseMethod { mOkHttpClient, httpUrl ); + mDavResource.setFollowRedirects(false); } public DavResource getDavResource() {