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; | 5 package org.chromium.net; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
9 | 9 |
10 import org.apache.http.HttpStatus; | 10 import org.apache.http.HttpStatus; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 214 |
215 mHttpStatusCode = mConnection.getResponseCode(); | 215 mHttpStatusCode = mConnection.getResponseCode(); |
216 mContentType = mConnection.getContentType(); | 216 mContentType = mConnection.getContentType(); |
217 mContentLength = mConnection.getContentLength(); | 217 mContentLength = mConnection.getContentLength(); |
218 if (mContentLengthLimit > 0 && mContentLength > mContentLengthLimit | 218 if (mContentLengthLimit > 0 && mContentLength > mContentLengthLimit |
219 && mCancelIfContentLengthOverLimit) { | 219 && mCancelIfContentLengthOverLimit) { |
220 onContentLengthOverLimit(); | 220 onContentLengthOverLimit(); |
221 return; | 221 return; |
222 } | 222 } |
223 | 223 |
224 mListener.onResponseStarted(this); | |
225 | |
224 mResponseStream = isError(mHttpStatusCode) ? mConnection | 226 mResponseStream = isError(mHttpStatusCode) ? mConnection |
225 .getErrorStream() | 227 .getErrorStream() |
226 : stream; | 228 : stream; |
227 | 229 |
228 if (mResponseStream != null | 230 if (mResponseStream != null |
229 && "gzip".equals(mConnection.getContentEncoding())) { | 231 && "gzip".equals(mConnection.getContentEncoding())) { |
230 mResponseStream = new GZIPInputStream(mResponseStream); | 232 mResponseStream = new GZIPInputStream(mResponseStream); |
231 mContentLength = -1; | 233 mContentLength = -1; |
232 } | 234 } |
233 | 235 |
234 if (mOffset != 0) { | 236 if (mOffset != 0) { |
235 // The server may ignore the request for a byte range. | 237 // The server may ignore the request for a byte range. |
236 if (mHttpStatusCode == HttpStatus.SC_OK) { | 238 if (mHttpStatusCode == HttpStatus.SC_OK) { |
237 if (mContentLength != -1) { | 239 if (mContentLength != -1) { |
238 mContentLength -= mOffset; | 240 mContentLength -= mOffset; |
239 } | 241 } |
240 mSkippingToOffset = true; | 242 mSkippingToOffset = true; |
241 } else { | 243 } else { |
242 mSize = mOffset; | 244 mSize = mOffset; |
243 } | 245 } |
244 } | 246 } |
245 | 247 |
246 if (mResponseStream != null) { | 248 if (mResponseStream != null) { |
247 readingResponse = true; | 249 readingResponse = true; |
248 readResponseAsync(); | 250 readResponseAsync(); |
249 } | 251 } |
250 } catch (IOException e) { | 252 } catch (IOException e) { |
251 mException = e; | 253 mException = e; |
252 } finally { | 254 } finally { |
255 if (mPostDataChannel != null) { | |
256 try { | |
257 mPostDataChannel.close(); | |
258 } catch (IOException e) { | |
259 // Ignore | |
260 } | |
261 } | |
262 | |
253 // Don't call onRequestComplete yet if we are reading the response | 263 // Don't call onRequestComplete yet if we are reading the response |
254 // on a separate thread | 264 // on a separate thread |
255 if (!readingResponse) { | 265 if (!readingResponse) { |
256 mListener.onRequestComplete(this); | 266 mListener.onRequestComplete(this); |
257 } | 267 } |
258 } | 268 } |
259 } | 269 } |
260 | 270 |
261 private void uploadData() throws IOException { | 271 private void uploadData() throws IOException { |
262 mConnection.setDoOutput(true); | 272 mConnection.setDoOutput(true); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 @Override | 428 @Override |
419 public long getContentLength() { | 429 public long getContentLength() { |
420 return mContentLength; | 430 return mContentLength; |
421 } | 431 } |
422 | 432 |
423 @Override | 433 @Override |
424 public String getContentType() { | 434 public String getContentType() { |
425 return mContentType; | 435 return mContentType; |
426 } | 436 } |
427 | 437 |
438 | |
439 @Override | |
440 public String getHeader(String name) { | |
441 if (mConnection == null) { | |
442 throw new IllegalStateException("Response headers not available"); | |
tonycuadra
2014/05/19 17:32:24
extra space after "header not"
mef
2014/05/20 18:04:34
Done.
| |
443 } | |
444 return mConnection.getHeaderField(name); | |
445 } | |
446 | |
428 private void validateNotStarted() { | 447 private void validateNotStarted() { |
429 if (mStarted) { | 448 if (mStarted) { |
430 throw new IllegalStateException("Request already started"); | 449 throw new IllegalStateException("Request already started"); |
431 } | 450 } |
432 } | 451 } |
433 } | 452 } |
OLD | NEW |