Commit 40aef8e2 authored by Ricki Hirner's avatar Ricki Hirner

Process HTTP header list values correctly

* HttpUtils: listHeader helper to get list values of an okhttp Response header
parent 94a5ee4a
......@@ -67,9 +67,8 @@ public class DavResource {
/**
* Creates a new DavResource which represents a WebDAV resource at the given location.
* @param log #{@link Logger} which will be used for logging, or null for default
* @param httpClient #{@link OkHttpClient} to access this object, must not follow redirects
* @param httpClient #{@link OkHttpClient} to access this object
* @param location location of the WebDAV resource
* @throws IllegalArgumentException when httpClient follows redirects
*/
public DavResource(Logger log, OkHttpClient httpClient, HttpUrl location) {
this.log = log != null ? log : Constants.log;
......@@ -103,9 +102,8 @@ public class DavResource {
.build()).execute();
checkStatus(response);
for (String dav : response.headers("DAV"))
for (String capability : TextUtils.split(dav, ","))
capabilities.add(capability.trim());
for (String capability : HttpUtils.listHeader(response, "DAV"))
capabilities.add(capability.trim());
}
......
......@@ -8,6 +8,8 @@
package at.bitfire.dav4android;
import android.text.TextUtils;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
......@@ -16,11 +18,16 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.RequiredArgsConstructor;
import okhttp3.Response;
public class HttpUtils {
private static final Pattern authSchemeWithParam = Pattern.compile("^([^ \"]+) +(.*)$");
public static String[] listHeader(Response response, String name) {
String value = TextUtils.join(",", response.headers(name));
return TextUtils.split(value, " *, *");
}
public static List<AuthScheme> parseWwwAuthenticate(String[] wwwAuths) {
/* WWW-Authenticate = "WWW-Authenticate" ":" 1#challenge
......
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