mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Improved ETag parsing
This commit is contained in:
parent
092c790030
commit
f61b466124
@ -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
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user