First of all, you need to change the BasicNetwork.convertHeaders method to support multiple map values. Here is an example of a modified method:
protected static Map<String, List<String>> convertHeaders(Header[] headers) { Map<String, List<String>> result = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); for (int i = 0; i < headers.length; i++) { Header header = headers[i]; List<String> list = result.get(header.getName()); if (list == null) { list = new ArrayList<String>(1); list.add(header.getValue()); result.put(header.getName(), list); } else list.add(header.getValue()); } return result; }
The next thing you need to do is change the DiskBasedCache.writeStringStringMap and DiskBasedCache.readStringStringMap methods. They must support multiple values. The following are modified methods and helper methods:
static void writeStringStringMap(Map<String, List<String>> map, OutputStream os) throws IOException { if (map != null) { writeInt(os, map.size()); for (Map.Entry<String, List<String>> entry : map.entrySet()) { writeString(os, entry.getKey()); writeString(os, joinStringsList(entry.getValue())); } } else { writeInt(os, 0); } } static Map<String, List<String>> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, List<String>> result = (size == 0) ? Collections.<String, List<String>>emptyMap() : new HashMap<String, List<String>>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, parseNullStringsList(value)); } return result; } static List<String> parseNullStringsList(String str) { String[] strs = str.split("\0"); return Arrays.asList(strs); } static String joinStringsList(List<String> list) { StringBuilder ret = new StringBuilder(); boolean first = true; for (String str : list) { if (first) first = false; else ret.append("\0"); ret.append(str); } return ret.toString(); }
And the last thing is the HttpHeaderParser class. You must force its parseCacheHeaders method to support multiple values. To do this, use the following helper method:
public static String getHeaderValue(List<String> list) { if ((list == null) || list.isEmpty()) return null; return list.get(0); }
And the last thing to change is a bunch of places to replace
Map<String, String>
to
Map<String, List<String>>
Use this IDE.
Ruslan Yanchyshyn Mar 11 '15 at 10:33 2015-03-11 10:33
source share