summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2014-11-10 10:06:14 -0800
committerJeff Sharkey <jsharkey@android.com>2014-11-10 10:11:31 -0800
commit0032d17c1ddbabfea528eb55ca5d03281871f848 (patch)
treec5b8bb2dbfcfc0a7673b235890b8685f11b4255f /src
parent83cf6d5b7504abda93420d04efa4f96d5f86a1df (diff)
downloadandroid_packages_providers_DownloadProvider-0032d17c1ddbabfea528eb55ca5d03281871f848.zip
android_packages_providers_DownloadProvider-0032d17c1ddbabfea528eb55ca5d03281871f848.tar.gz
android_packages_providers_DownloadProvider-0032d17c1ddbabfea528eb55ca5d03281871f848.tar.bz2
Connection: close is enough to know length.
Now that we're defeating connection reuse, we have one additional type of response where the length is known. Bug: 18306491 Change-Id: I19657c565238f07fd89a55a5dbf1e85748f6e7c3
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/DownloadThread.java14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index c0f5a5e..2493ada 100644
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -439,12 +439,16 @@ public class DownloadThread implements Runnable {
*/
private void transferData(HttpURLConnection conn) throws StopRequestException {
- // To detect when we're really finished, we either need a length or
- // chunked encoding.
+ // To detect when we're really finished, we either need a length, closed
+ // connection, or chunked encoding.
final boolean hasLength = mInfoDelta.mTotalBytes != -1;
- final String transferEncoding = conn.getHeaderField("Transfer-Encoding");
- final boolean isChunked = "chunked".equalsIgnoreCase(transferEncoding);
- if (!hasLength && !isChunked) {
+ final boolean isConnectionClose = "close".equalsIgnoreCase(
+ conn.getHeaderField("Connection"));
+ final boolean isEncodingChunked = "chunked".equalsIgnoreCase(
+ conn.getHeaderField("Transfer-Encoding"));
+
+ final boolean finishKnown = hasLength || isConnectionClose || isEncodingChunked;
+ if (!finishKnown) {
throw new StopRequestException(
STATUS_CANNOT_RESUME, "can't know size of download, giving up");
}