From: David A. Velasco Date: Tue, 8 Oct 2013 09:28:57 +0000 (+0200) Subject: Merge branch 'develop' into release-1.4.6 X-Git-Tag: oc-android-1.4.6~6^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7d512002911ff7ed915995bf58b12e69783438bd?hp=86f7f0cc3c316fc9f1caeedc5ba63ccfb7a0ffd7 Merge branch 'develop' into release-1.4.6 --- diff --git a/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java b/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java index 3f453968..103cd04a 100644 --- a/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java +++ b/src/eu/alefzero/webdav/ChunkFromFileChannelRequestEntity.java @@ -120,11 +120,14 @@ public class ChunkFromFileChannelRequestEntity implements RequestEntity, Progres mChannel.position(mOffset); long size = mFile.length(); if (size == 0) size = -1; - while (mChannel.position() < mOffset + mChunkSize && mChannel.position() < mChannel.size()) { + long maxCount = Math.min(mOffset + mChunkSize, mChannel.size()); + while (mChannel.position() < maxCount) { readCount = mChannel.read(mBuffer); out.write(mBuffer.array(), 0, readCount); mBuffer.clear(); - mTransferred += readCount; + if (mTransferred < maxCount) { // condition to avoid accumulate progress for repeated chunks + mTransferred += readCount; + } synchronized (mDataTransferListeners) { it = mDataTransferListeners.iterator(); while (it.hasNext()) { diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index cedf9267..f25e3906 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -24,12 +24,14 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpConnectionManager; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpVersion; +import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthPolicy; import org.apache.commons.httpclient.auth.AuthScope; @@ -48,6 +50,8 @@ import com.owncloud.android.network.BearerCredentials; import android.net.Uri; public class WebdavClient extends HttpClient { + private static final int MAX_REDIRECTIONS_COUNT = 3; + private Uri mUri; private Credentials mCredentials; private boolean mFollowRedirects; @@ -160,15 +164,39 @@ public class WebdavClient extends HttpClient { @Override public int executeMethod(HttpMethod method) throws IOException, HttpException { + boolean customRedirectionNeeded = false; try { method.setFollowRedirects(mFollowRedirects); } catch (Exception e) { - + if (mFollowRedirects) Log_OC.d(TAG, "setFollowRedirects failed for " + method.getName() + " method, custom redirection will be used"); + customRedirectionNeeded = mFollowRedirects; } if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) { method.setRequestHeader("Cookie", mSsoSessionCookie); } - return super.executeMethod(method); + int status = super.executeMethod(method); + int redirectionsCount = 0; + while (customRedirectionNeeded && + redirectionsCount < MAX_REDIRECTIONS_COUNT && + ( status == HttpStatus.SC_MOVED_PERMANENTLY || + status == HttpStatus.SC_MOVED_TEMPORARILY || + status == HttpStatus.SC_TEMPORARY_REDIRECT) + ) { + + Header location = method.getResponseHeader("Location"); + if (location != null) { + Log_OC.d(TAG, "Location to redirect: " + location.getValue()); + method.setURI(new URI(location.getValue(), true)); + status = super.executeMethod(method); + redirectionsCount++; + + } else { + Log_OC.d(TAG, "No location to redirect!"); + status = HttpStatus.SC_NOT_FOUND; + } + } + + return status; }