| 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; | |
| 11 | |
| 12 import java.io.FileNotFoundException; | 10 import java.io.FileNotFoundException; |
| 13 import java.io.IOException; | 11 import java.io.IOException; |
| 14 import java.io.InputStream; | 12 import java.io.InputStream; |
| 15 import java.io.OutputStream; | 13 import java.io.OutputStream; |
| 16 import java.net.HttpURLConnection; | 14 import java.net.HttpURLConnection; |
| 17 import java.net.ProtocolException; | 15 import java.net.ProtocolException; |
| 18 import java.net.URL; | 16 import java.net.URL; |
| 19 import java.nio.ByteBuffer; | 17 import java.nio.ByteBuffer; |
| 20 import java.nio.channels.ReadableByteChannel; | 18 import java.nio.channels.ReadableByteChannel; |
| 21 import java.nio.channels.WritableByteChannel; | 19 import java.nio.channels.WritableByteChannel; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 : stream; | 274 : stream; |
| 277 | 275 |
| 278 if (mResponseStream != null | 276 if (mResponseStream != null |
| 279 && "gzip".equals(mConnection.getContentEncoding())) { | 277 && "gzip".equals(mConnection.getContentEncoding())) { |
| 280 mResponseStream = new GZIPInputStream(mResponseStream); | 278 mResponseStream = new GZIPInputStream(mResponseStream); |
| 281 mContentLength = -1; | 279 mContentLength = -1; |
| 282 } | 280 } |
| 283 | 281 |
| 284 if (mOffset != 0) { | 282 if (mOffset != 0) { |
| 285 // The server may ignore the request for a byte range. | 283 // The server may ignore the request for a byte range. |
| 286 if (mHttpStatusCode == HttpStatus.SC_OK) { | 284 if (mHttpStatusCode == HttpURLConnection.HTTP_OK) { |
| 287 if (mContentLength != -1) { | 285 if (mContentLength != -1) { |
| 288 mContentLength -= mOffset; | 286 mContentLength -= mOffset; |
| 289 } | 287 } |
| 290 mSkippingToOffset = true; | 288 mSkippingToOffset = true; |
| 291 } else { | 289 } else { |
| 292 mSize = mOffset; | 290 mSize = mOffset; |
| 293 } | 291 } |
| 294 } | 292 } |
| 295 | 293 |
| 296 if (mResponseStream != null) { | 294 if (mResponseStream != null) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 438 |
| 441 @Override | 439 @Override |
| 442 public int getHttpStatusCode() { | 440 public int getHttpStatusCode() { |
| 443 int httpStatusCode = mHttpStatusCode; | 441 int httpStatusCode = mHttpStatusCode; |
| 444 | 442 |
| 445 // If we have been able to successfully resume a previously interrupted | 443 // If we have been able to successfully resume a previously interrupted |
| 446 // download, | 444 // download, |
| 447 // the status code will be 206, not 200. Since the rest of the | 445 // the status code will be 206, not 200. Since the rest of the |
| 448 // application is | 446 // application is |
| 449 // expecting 200 to indicate success, we need to fake it. | 447 // expecting 200 to indicate success, we need to fake it. |
| 450 if (httpStatusCode == HttpStatus.SC_PARTIAL_CONTENT) { | 448 if (httpStatusCode == HttpURLConnection.HTTP_PARTIAL) { |
| 451 httpStatusCode = HttpStatus.SC_OK; | 449 httpStatusCode = HttpURLConnection.HTTP_OK; |
| 452 } | 450 } |
| 453 return httpStatusCode; | 451 return httpStatusCode; |
| 454 } | 452 } |
| 455 | 453 |
| 456 @Override | 454 @Override |
| 457 public String getHttpStatusText() { | 455 public String getHttpStatusText() { |
| 458 return mHttpStatusText; | 456 return mHttpStatusText; |
| 459 } | 457 } |
| 460 | 458 |
| 461 @Override | 459 @Override |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 } | 518 } |
| 521 return mConnection.getHeaderFields(); | 519 return mConnection.getHeaderFields(); |
| 522 } | 520 } |
| 523 | 521 |
| 524 private void validateNotStarted() { | 522 private void validateNotStarted() { |
| 525 if (mStarted) { | 523 if (mStarted) { |
| 526 throw new IllegalStateException("Request already started"); | 524 throw new IllegalStateException("Request already started"); |
| 527 } | 525 } |
| 528 } | 526 } |
| 529 } | 527 } |
| OLD | NEW |