From 5224c6fbf20b4803a580ef449ab87ebfbbfedb78 Mon Sep 17 00:00:00 2001 From: Steve Howard Date: Wed, 14 Jul 2010 11:30:59 -0700 Subject: Support for custom HTTP headers on download requests Provider changes: * new many-to-one DB table holding headers for each download. since there was no real migration logic in DownloadProvider, I implemented some. * DownloadProvider.insert() reads request headers out of the ContentValues and puts them into the new table * DownloadProvider.query() supports a new URI form, download/#/headers, to fetch the headers associated with a download * DownloadProvider.delete() removes request headers from this table Service changes: * made DownloadInfo store request headers upon initialization. While I was at it, I refactored the initialization logic into DownloadInfo to get rid of the massive 24-parameter constructor. The right next step would be to move the update logic into DownloadInfo and merge it with the initialization logic; however, I realized that headers don't need to be updatable, and in the future, we won't need the update logic at all, so i didn't bother touching the update code. * made DownloadThread read headers from the DownloadInfo and include them in the request; merged the custom Cookie and Referer logic into this logic Also added a couple new test cases for this stuff. Change-Id: I421ce1f0a694e815f2e099795182393650fcb3ff --- .../downloads/PublicApiFunctionalTest.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java index e3b278bc..e9195609 100644 --- a/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java +++ b/tests/src/com/android/providers/downloads/PublicApiFunctionalTest.java @@ -20,6 +20,7 @@ import android.database.Cursor; import android.net.DownloadManager; import android.net.Uri; import android.os.Environment; +import android.util.Log; import tests.http.RecordedRequest; import java.io.File; @@ -271,6 +272,27 @@ public class PublicApiFunctionalTest extends AbstractDownloadManagerFunctionalTe } } + public void testRequestHeaders() throws Exception { + enqueueEmptyResponse(HTTP_OK); + Download download = enqueueRequest(getRequest().setRequestHeader("Header1", "value1") + .setRequestHeader("Header2", "value2")); + RecordedRequest request = download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL); + + assertTrue(request.getHeaders().contains("Header1: value1")); + assertTrue(request.getHeaders().contains("Header2: value2")); + } + + public void testDelete() throws Exception { + Download download = enqueueRequest(getRequest().setRequestHeader("header", "value")); + mManager.remove(download.mId); + Cursor cursor = mManager.query(new DownloadManager.Query()); + try { + assertEquals(0, cursor.getCount()); + } finally { + cursor.close(); + } + } + private DownloadManager.Request getRequest() throws MalformedURLException { return getRequest(getServerUri(REQUEST_PATH)); } -- cgit v1.2.3