Process redirect for GET and PUT

* process redirect for GET and PUT
* new ConflictException for status 409
* handle missing properties (propstat 404) in multi-get requests when updating properties
* tests
parent 2083d075
......@@ -235,11 +235,11 @@ public class BasicDigestAuthenticator implements Authenticator {
else if ("auth-int".equals(qop))
qopAuthInt = true;
// prefer auth
if (qopAuth)
return Auth;
else if (qopAuthInt)
// prefer auth-int as it provides more protection
if (qopAuthInt)
return AuthInt;
else if (qopAuth)
return Auth;
}
return null;
}
......
......@@ -78,10 +78,28 @@ public class PropertyCollection {
}
public void merge(PropertyCollection another) {
public void merge(PropertyCollection another, boolean removeNullValues) {
Map<Property.Name, Property> properties = another.getMap();
for (Property.Name name : properties.keySet())
put(name, properties.get(name));
for (Property.Name name : properties.keySet()) {
Property prop = properties.get(name);
if (!removeNullValues || prop != null)
put(name, prop);
else
remove(name);
}
}
public void nullAllValues() {
if (properties == null)
return;
for (String namespace : properties.keySet()) {
Map<String, Property> nsProperties = properties.get(namespace);
if (nsProperties != null) {
for (String name : nsProperties.keySet())
nsProperties.put(name, null);
}
}
}
......
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.dav4android.exception;
import com.squareup.okhttp.Response;
import java.net.HttpURLConnection;
public class ConflictException extends HttpException {
public ConflictException(Response response) {
super(response);
}
public ConflictException(String message) {
super(HttpURLConnection.HTTP_CONFLICT, message);
}
}
......@@ -24,6 +24,14 @@ public class HttpException extends Exception implements Serializable {
public final String request, response;
public HttpException(String message) {
super(message);
this.message = message;
this.status = -1;
this.request = this.response = null;
}
public HttpException(int status, String message) {
super(status + " " + message);
this.status = status;
......
......@@ -10,6 +10,8 @@ package at.bitfire.dav4android.exception;
import com.squareup.okhttp.Response;
import java.net.HttpURLConnection;
public class NotFoundException extends HttpException {
public NotFoundException(Response response) {
......@@ -17,7 +19,7 @@ public class NotFoundException extends HttpException {
}
public NotFoundException(String message) {
super(404, message);
super(HttpURLConnection.HTTP_NOT_FOUND, message);
}
}
......@@ -10,6 +10,8 @@ package at.bitfire.dav4android.exception;
import com.squareup.okhttp.Response;
import java.net.HttpURLConnection;
public class PreconditionFailedException extends HttpException {
public PreconditionFailedException(Response response) {
......@@ -17,7 +19,7 @@ public class PreconditionFailedException extends HttpException {
}
public PreconditionFailedException(String message) {
super(412, message);
super(HttpURLConnection.HTTP_PRECON_FAILED, message);
}
}
......@@ -11,6 +11,7 @@ package at.bitfire.dav4android.exception;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.internal.http.HttpDate;
import java.net.HttpURLConnection;
import java.util.Calendar;
import java.util.Date;
......@@ -21,7 +22,7 @@ public class ServiceUnavailableException extends HttpException {
public Date retryAfter;
public ServiceUnavailableException(String message) {
super(503, message);
super(HttpURLConnection.HTTP_UNAVAILABLE, message);
retryAfter = null;
}
......
......@@ -10,6 +10,8 @@ package at.bitfire.dav4android.property;
import android.util.Log;
import com.squareup.okhttp.MediaType;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
......@@ -29,6 +31,10 @@ public class GetContentType implements Property {
private GetContentType() {}
public GetContentType(MediaType mediaType) {
type = mediaType.toString();
}
public static class Factory implements PropertyFactory {
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment