Skip to content

Commit

Permalink
Close mozilla-mobile#8823 allow data urls to be download
Browse files Browse the repository at this point in the history
using the new gv downloaded api
  • Loading branch information
Amejia481 committed Oct 28, 2020
1 parent 1befbad commit ca3cd2b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>? = null, body: String? = null, method: String = "GET") {
val server = mock<MockWebServer>()
whenever(server.url(any())).thenReturn(mock())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>? = null, body: String? = null, method: String = "GET") {
val server = mock<MockWebServer>()
whenever(server.url(any())).thenReturn(mock())
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ca3cd2b

Please sign in to comment.