From ca3cd2b7baa771e18dc58a0a50e072f241936fec Mon Sep 17 00:00:00 2001 From: Arturo Mejia Date: Wed, 28 Oct 2020 17:29:34 -0400 Subject: [PATCH] Close #8823 allow data urls to be download using the new gv downloaded api --- .../browser/engine/gecko/fetch/GeckoViewFetchClient.kt | 3 ++- .../engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt | 7 +++++++ .../browser/engine/gecko/fetch/GeckoViewFetchClient.kt | 3 ++- .../engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt | 7 +++++++ docs/changelog.md | 3 +++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt b/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt index 3d987b5333e..3e013e6d2c1 100644 --- a/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt +++ b/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt @@ -104,10 +104,11 @@ private fun WebRequest.Builder.addBodyFrom(request: Request): WebRequest.Builder } internal fun WebResponse.toResponse(isBlobUri: Boolean): Response { + val isDataUri = uri.startsWith("data:") val headers = translateHeaders(this) // We use the same API for blobs and HTTP requests, but blobs won't receive a status code. // If no exception is thrown we assume success. - val status = if (isBlobUri) SUCCESS else statusCode + val status = if (isBlobUri || isDataUri) SUCCESS else statusCode return Response( uri, status, diff --git a/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt b/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt index a6c6931b352..13303eb8d07 100644 --- a/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt +++ b/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt @@ -269,6 +269,13 @@ class GeckoViewFetchUnitTestCases : FetchTestCases() { assertEquals(Response.SUCCESS, builder.toResponse(isBlobUri = true).status) } + @Test + fun toResponseMustReturn200ForDataUrls() { + val builder = WebResponse.Builder("data:,Hello%2C%20World!").statusCode(0).build() + + assertEquals(Response.SUCCESS, builder.toResponse(isBlobUri = true).status) + } + private fun mockRequest(headerMap: Map? = null, body: String? = null, method: String = "GET") { val server = mock() whenever(server.url(any())).thenReturn(mock()) diff --git a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt index 3d987b5333e..3e013e6d2c1 100644 --- a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt +++ b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchClient.kt @@ -104,10 +104,11 @@ private fun WebRequest.Builder.addBodyFrom(request: Request): WebRequest.Builder } internal fun WebResponse.toResponse(isBlobUri: Boolean): Response { + val isDataUri = uri.startsWith("data:") val headers = translateHeaders(this) // We use the same API for blobs and HTTP requests, but blobs won't receive a status code. // If no exception is thrown we assume success. - val status = if (isBlobUri) SUCCESS else statusCode + val status = if (isBlobUri || isDataUri) SUCCESS else statusCode return Response( uri, status, diff --git a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt index a6c6931b352..13303eb8d07 100644 --- a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt +++ b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/fetch/GeckoViewFetchUnitTestCases.kt @@ -269,6 +269,13 @@ class GeckoViewFetchUnitTestCases : FetchTestCases() { assertEquals(Response.SUCCESS, builder.toResponse(isBlobUri = true).status) } + @Test + fun toResponseMustReturn200ForDataUrls() { + val builder = WebResponse.Builder("data:,Hello%2C%20World!").statusCode(0).build() + + assertEquals(Response.SUCCESS, builder.toResponse(isBlobUri = true).status) + } + private fun mockRequest(headerMap: Map? = null, body: String? = null, method: String = "GET") { val server = mock() whenever(server.url(any())).thenReturn(mock()) diff --git a/docs/changelog.md b/docs/changelog.md index 810efc47ab6..f4e9802f2d6 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -12,6 +12,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/.config.yml) +* **feature-downloads** + * 🚒 Bug fixed [issue #8823](https://github.com/mozilla-mobile/android-components/issues/8823) Downloads for data URLs were failing on nightly and beta more details in the [Fenix issue](https://github.com/mozilla-mobile/fenix/issues/16228#issuecomment-717976737). + # 64.0.0 * [Commits](https://github.com/mozilla-mobile/android-components/compare/v63.0.0...v64.0.0)