diff --git a/src/com/owncloud/android/lib/common/network/WebdavEntry.java b/src/com/owncloud/android/lib/common/network/WebdavEntry.java index 1979cbc8..64d21e7e 100644 --- a/src/com/owncloud/android/lib/common/network/WebdavEntry.java +++ b/src/com/owncloud/android/lib/common/network/WebdavEntry.java @@ -129,7 +129,7 @@ public class WebdavEntry { prop = propSet.get(DavPropertyName.GETETAG); if (prop != null) { mEtag = (String) prop.getValue(); - mEtag = mEtag.substring(1, mEtag.length()-1); + mEtag = WebdavUtils.parseEtag(mEtag); } // {DAV:}quota-used-bytes diff --git a/src/com/owncloud/android/lib/common/network/WebdavUtils.java b/src/com/owncloud/android/lib/common/network/WebdavUtils.java index bf2e986d..c5d2e829 100644 --- a/src/com/owncloud/android/lib/common/network/WebdavUtils.java +++ b/src/com/owncloud/android/lib/common/network/WebdavUtils.java @@ -32,6 +32,8 @@ import java.util.Locale; import android.net.Uri; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpMethod; import org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; import org.apache.jackrabbit.webdav.xml.Namespace; @@ -131,4 +133,47 @@ public class WebdavUtils { return propSet; } + + /** + * + * @param rawEtag + * @return + */ + public static String parseEtag(String rawEtag) { + if (rawEtag == null || rawEtag.length() == 0) { + return ""; + } + if (rawEtag.endsWith("-gzip")) { + rawEtag = rawEtag.substring(0, rawEtag.length() - 5); + } + if (rawEtag.length() >= 2 && rawEtag.startsWith("\"") && rawEtag.endsWith("\"")) { + rawEtag = rawEtag.substring(1, rawEtag.length() - 1); + } + return rawEtag; + } + + + /** + * + * @param method + * @return + */ + public static String getEtagFromResponse(HttpMethod method) { + Header eTag = method.getResponseHeader("OC-ETag"); + if (eTag == null) { + eTag = method.getResponseHeader("oc-etag"); + } + if (eTag == null) { + eTag = method.getResponseHeader("ETag"); + } + if (eTag == null) { + eTag = method.getResponseHeader("etag"); + } + String result = ""; + if (eTag != null) { + result = parseEtag(eTag.getValue()); + } + return result; + } + } diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index 3873b5ec..b9c404c3 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -150,16 +150,9 @@ public class DownloadRemoteFileOperation extends RemoteOperation { } else { Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath); } - Header eTag = mGet.getResponseHeader("ETag"); - if (eTag == null) { - eTag = mGet.getResponseHeader("etag"); - } - if (eTag != null) { - mEtag = eTag.getValue(); - if (mEtag.charAt(0) == '"' && mEtag.charAt(mEtag.length() - 1) == '"') { - mEtag = mEtag.substring(1, mEtag.length() - 1); - } - } else { + + mEtag = WebdavUtils.getEtagFromResponse(mGet); + if (mEtag.length() == 0) { Log_OC.e(TAG, "Could not read eTag from response downloading " + mRemotePath); }