OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.net.urlconnection; | 5 package org.chromium.net.urlconnection; |
6 | 6 |
7 import android.util.Pair; | 7 import android.util.Pair; |
8 | 8 |
9 import org.chromium.base.Log; | 9 import org.chromium.base.Log; |
10 import org.chromium.net.ExtendedResponseInfo; | 10 import org.chromium.net.ExtendedResponseInfo; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 List<String> values = map.get(fieldName); | 137 List<String> values = map.get(fieldName); |
138 return values.get(values.size() - 1); | 138 return values.get(values.size() - 1); |
139 } | 139 } |
140 | 140 |
141 /** | 141 /** |
142 * Returns the name of the header field at the given position {@code pos}, o
r {@code null} | 142 * Returns the name of the header field at the given position {@code pos}, o
r {@code null} |
143 * if there are fewer than {@code pos} fields. | 143 * if there are fewer than {@code pos} fields. |
144 */ | 144 */ |
145 @Override | 145 @Override |
146 public final String getHeaderFieldKey(int pos) { | 146 public final String getHeaderFieldKey(int pos) { |
147 Pair<String, String> header = getHeaderFieldPair(pos); | 147 Map.Entry<String, String> header = getHeaderFieldEntry(pos); |
148 if (header == null) { | 148 if (header == null) { |
149 return null; | 149 return null; |
150 } | 150 } |
151 return header.first; | 151 return header.getKey(); |
152 } | 152 } |
153 | 153 |
154 /** | 154 /** |
155 * Returns the header value at the field position {@code pos} or {@code null
} if the header | 155 * Returns the header value at the field position {@code pos} or {@code null
} if the header |
156 * has fewer than {@code pos} fields. | 156 * has fewer than {@code pos} fields. |
157 */ | 157 */ |
158 @Override | 158 @Override |
159 public final String getHeaderField(int pos) { | 159 public final String getHeaderField(int pos) { |
160 Pair<String, String> header = getHeaderFieldPair(pos); | 160 Map.Entry<String, String> header = getHeaderFieldEntry(pos); |
161 if (header == null) { | 161 if (header == null) { |
162 return null; | 162 return null; |
163 } | 163 } |
164 return header.second; | 164 return header.getValue(); |
165 } | 165 } |
166 | 166 |
167 /** | 167 /** |
168 * Returns an InputStream for reading data from the resource pointed by this | 168 * Returns an InputStream for reading data from the resource pointed by this |
169 * {@link java.net.URLConnection}. | 169 * {@link java.net.URLConnection}. |
170 * @throws FileNotFoundException if http response code is equal or greater | 170 * @throws FileNotFoundException if http response code is equal or greater |
171 * than {@link HTTP_BAD_REQUEST}. | 171 * than {@link HTTP_BAD_REQUEST}. |
172 * @throws IOException If the request gets a network error or HTTP error | 172 * @throws IOException If the request gets a network error or HTTP error |
173 * status code, or if the caller tried to read the response body | 173 * status code, or if the caller tried to read the response body |
174 * of a redirect when redirects are disabled. | 174 * of a redirect when redirects are disabled. |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 throw mException; | 514 throw mException; |
515 } else if (mResponseInfo == null) { | 515 } else if (mResponseInfo == null) { |
516 throw new NullPointerException( | 516 throw new NullPointerException( |
517 "Response info is null when there is no exception."); | 517 "Response info is null when there is no exception."); |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 /** | 521 /** |
522 * Helper method to return the response header field at position pos. | 522 * Helper method to return the response header field at position pos. |
523 */ | 523 */ |
524 private Pair<String, String> getHeaderFieldPair(int pos) { | 524 private Map.Entry<String, String> getHeaderFieldEntry(int pos) { |
525 try { | 525 try { |
526 getResponse(); | 526 getResponse(); |
527 } catch (IOException e) { | 527 } catch (IOException e) { |
528 return null; | 528 return null; |
529 } | 529 } |
530 List<Pair<String, String>> headers = | 530 List<Map.Entry<String, String>> headers = mResponseInfo.getAllHeadersAsL
ist(); |
531 mResponseInfo.getAllHeadersAsList(); | |
532 if (pos >= headers.size()) { | 531 if (pos >= headers.size()) { |
533 return null; | 532 return null; |
534 } | 533 } |
535 return headers.get(pos); | 534 return headers.get(pos); |
536 } | 535 } |
537 | 536 |
538 /** | 537 /** |
539 * Returns whether the client has used {@link #setChunkedStreamingMode} to | 538 * Returns whether the client has used {@link #setChunkedStreamingMode} to |
540 * set chunked encoding for upload. | 539 * set chunked encoding for upload. |
541 */ | 540 */ |
542 private boolean isChunkedUpload() { | 541 private boolean isChunkedUpload() { |
543 return chunkLength > 0; | 542 return chunkLength > 0; |
544 } | 543 } |
545 } | 544 } |
OLD | NEW |