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..0d965000c72e1b844a83fc29c1e80cc6aac7d03b 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,77 @@ 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) { |
| + return Collections.emptyMap(); |
| + } |
| + 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) { |
|
mef
2015/01/30 16:22:52
Is implementation of getHeaderField enough to supp
xunjieli
2015/01/30 18:22:58
We can rely on the default implementations which r
|
| + 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 { |
|
mef
2015/01/30 16:22:52
nit: maybe factor out most of getHeaderField{Key}
xunjieli
2015/01/30 18:22:58
Done.
|
| + 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 |