Chromium Code Reviews| Index: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java |
| diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java |
| index 9c308ae1f5fba209df0e7c83a9db181bbcb233e6..8fe6bf50562d66af4f1cea549079d63a71fa9933 100644 |
| --- a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java |
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java |
| @@ -114,6 +114,79 @@ public class CronetHttpURLConnection extends HttpURLConnection { |
| } |
| /** |
| + * Returns an unmodifiable map of the response-header fields and values. |
| + */ |
| + @Override |
| + public Map<String, List<String>> getHeaderFields() { |
| + try { |
| + connect(); |
| + } catch (IOException e) { |
| + // Default implementation returns an empty map on K, but returns |
| + // null on L. |
| + return null; |
|
miloslav
2015/01/20 15:25:10
Do we really want to return null? That doesn't see
xunjieli
2015/01/20 16:12:21
Sorry about the confusion. I was mistaken. On k it
|
| + } |
| + return mResponseInfo.getAllHeaders(); |
| + } |
| + |
| + /** |
| + * Returns the value of the named header field. If called on a connection |
| + * that sets the same header multiple times with possibly different values, |
| + * only the last value is returned. |
| + */ |
| + @Override |
| + public final String getHeaderField(String fieldName) { |
| + try { |
| + connect(); |
| + } catch (IOException e) { |
| + return null; |
| + } |
| + Map<String, List<String>> map = mResponseInfo.getAllHeaders(); |
| + if (!map.containsKey(fieldName)) { |
| + return null; |
| + } |
| + List<String> values = map.get(fieldName); |
| + return values.get(values.size() - 1); |
| + } |
| + |
| + /** |
| + * Returns the name of the header field at the given position pos, or null |
| + * if there are fewer than pos fields. |
| + */ |
| + @Override |
| + public final String getHeaderFieldKey(int pos) { |
| + try { |
| + connect(); |
| + } catch (IOException e) { |
| + return null; |
| + } |
| + List<Pair<String, String>> headers = |
| + mResponseInfo.getAllHeadersAsList(); |
| + if (pos >= headers.size()) { |
| + return null; |
| + } |
| + return headers.get(pos).first; |
| + } |
| + |
| + /** |
| + * Returns the header value at the field position pos or null if the header |
| + * has fewer than pos fields. |
| + */ |
| + @Override |
| + public final String getHeaderField(int pos) { |
| + try { |
| + connect(); |
| + } catch (IOException e) { |
| + return null; |
| + } |
| + List<Pair<String, String>> headers = |
| + mResponseInfo.getAllHeadersAsList(); |
| + if (pos >= headers.size()) { |
| + return null; |
| + } |
| + return headers.get(pos).second; |
| + } |
| + |
| + /** |
| * Returns an InputStream for reading data from the resource pointed by this |
| * URLConnection. |
| * @throws FileNotFoundException if http response code is equal or greater |