diff options
| author | 2010-07-13 19:02:45 -0700 | |
|---|---|---|
| committer | 2010-07-15 10:22:50 -0700 | |
| commit | ea9147df00ee6e098cd02d901424ae5a4fe0fafd (patch) | |
| tree | e231aa36d5e6c3c941ffe2c5f9a679a88e31ed7d | |
| parent | 05940b2c04041d6b3b8d222f4acfd12faeeb6c9c (diff) | |
Interface support for custom HTTP headers in DL manager
* constants for new DB table, keys for including headers in a
DownloadProvider.insert() call, and new URIs for retrieving headers
* support in DownloadManager to pass headers to the provider
| -rw-r--r-- | core/java/android/net/DownloadManager.java | 12 | ||||
| -rw-r--r-- | core/java/android/provider/Downloads.java | 21 |
2 files changed, 31 insertions, 2 deletions
diff --git a/core/java/android/net/DownloadManager.java b/core/java/android/net/DownloadManager.java index 02b6210da88d..00b6864c0393 100644 --- a/core/java/android/net/DownloadManager.java +++ b/core/java/android/net/DownloadManager.java @@ -350,8 +350,7 @@ public class DownloadManager { } if (!mRequestHeaders.isEmpty()) { - // TODO request headers support - throw new UnsupportedOperationException(); + encodeHttpHeaders(values); } putIfNonNull(values, Downloads.COLUMN_TITLE, mTitle); @@ -367,6 +366,15 @@ public class DownloadManager { return values; } + private void encodeHttpHeaders(ContentValues values) { + int index = 0; + for (Map.Entry<String, String> entry : mRequestHeaders.entrySet()) { + String headerString = entry.getKey() + ": " + entry.getValue(); + values.put(Downloads.Impl.RequestHeaders.INSERT_KEY_PREFIX + index, headerString); + index++; + } + } + private void putIfNonNull(ContentValues contentValues, String key, String value) { if (value != null) { contentValues.put(key, value); diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java index 1a4f8c0f8a95..2a612fe5e301 100644 --- a/core/java/android/provider/Downloads.java +++ b/core/java/android/provider/Downloads.java @@ -1115,5 +1115,26 @@ public final class Downloads { * This download doesn't show in the UI or in the notifications. */ public static final int VISIBILITY_HIDDEN = 2; + + /** + * Constants related to HTTP request headers associated with each download. + */ + public static class RequestHeaders { + public static final String HEADERS_DB_TABLE = "request_headers"; + public static final String COLUMN_DOWNLOAD_ID = "download_id"; + public static final String COLUMN_HEADER = "header"; + public static final String COLUMN_VALUE = "value"; + + /** + * Path segment to add to a download URI to retrieve request headers + */ + public static final String URI_SEGMENT = "headers"; + + /** + * Prefix for ContentValues keys that contain HTTP header lines, to be passed to + * DownloadProvider.insert(). + */ + public static final String INSERT_KEY_PREFIX = "http_header_"; + } } } |