Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea9147df authored by Steve Howard's avatar Steve Howard
Browse files

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
parent 05940b2c
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -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);
+21 −0
Original line number Diff line number Diff line
@@ -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_";
        }
    }
}