Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f61b4661 authored by David A. Velasco's avatar David A. Velasco
Browse files

Improved ETag parsing

parent 092c7900
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -129,7 +129,7 @@ public class WebdavEntry {
            prop = propSet.get(DavPropertyName.GETETAG);
            prop = propSet.get(DavPropertyName.GETETAG);
            if (prop != null) {
            if (prop != null) {
                mEtag = (String) prop.getValue();
                mEtag = (String) prop.getValue();
                mEtag = mEtag.substring(1, mEtag.length()-1);
                mEtag = WebdavUtils.parseEtag(mEtag);
            }
            }


            // {DAV:}quota-used-bytes
            // {DAV:}quota-used-bytes
+45 −0
Original line number Original line Diff line number Diff line
@@ -32,6 +32,8 @@ import java.util.Locale;


import android.net.Uri;
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.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.xml.Namespace;
import org.apache.jackrabbit.webdav.xml.Namespace;
@@ -131,4 +133,47 @@ public class WebdavUtils {


        return propSet;
        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;
    }

}
}
+3 −10
Original line number Original line Diff line number Diff line
@@ -150,16 +150,9 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
                	} else {
                	} else {
                        Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath);
                        Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath);
                    }
                    }
                    Header eTag = mGet.getResponseHeader("ETag");

                    if (eTag == null) {
                    mEtag = WebdavUtils.getEtagFromResponse(mGet);
                        eTag = mGet.getResponseHeader("etag");
                    if (mEtag.length() == 0) {
                    }
                    if (eTag != null) {
                        mEtag = eTag.getValue();
                        if (mEtag.charAt(0) == '"' && mEtag.charAt(mEtag.length() - 1) == '"') {
                            mEtag = mEtag.substring(1, mEtag.length() - 1);
                        }
                    } else {
                        Log_OC.e(TAG, "Could not read eTag from response downloading " + mRemotePath);
                        Log_OC.e(TAG, "Could not read eTag from response downloading " + mRemotePath);
                    }
                    }