-
Notifications
You must be signed in to change notification settings - Fork 476
Closes #6314: Support fetching / downloading data URIs #6475
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6475 +/- ##
============================================
- Coverage 78.52% 78.38% -0.14%
+ Complexity 4687 4678 -9
============================================
Files 621 615 -6
Lines 22610 22519 -91
Branches 3309 3297 -12
============================================
- Hits 17754 17652 -102
- Misses 3496 3512 +16
+ Partials 1360 1355 -5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
| * @return The generated [Response] including the decoded bytes as body. | ||
| */ | ||
| @Suppress("TooGenericExceptionCaught") | ||
| fun fetchDataUri(request: Request): Response { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we put this into Client and make it protected (like defaultHeaders) so that it is not used outside of a Client implementation? This could now end up getting called by app code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense. Updated!
| @Test | ||
| override fun getDataUri() { | ||
| // We can't run this test case because Base64 encoding is not available but we can verify | ||
| // that we attempt to fetch the data URI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we run this with AndroidJUnit4 then we should be able to use the Base64 classes, I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, good catch! I've upgraded the lib and removed the test override as the base test is running fine now!
| val headers = MutableHeaders( | ||
| CONTENT_TYPE_HEADER to contentType, | ||
| CONTENT_LENGTH_HEADER to bytes.size.toString() | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, added another test case and made this more robust too.
|
bors r=Amejia481,pocmo |
6475: Closes #6314: Support fetching / downloading data URIs r=Amejia481,pocmo a=csadilek With this we can fetch from data URIs and downloads "just work" (we don't require any special handling). So, e.g. this works now (which is also used by uBlock to save backups): ```html <a href="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" download="backup.txt">Backup</a> ``` https://github.com/gorhill/uBlock/blob/08d370d32e648c2823e1bc31fcd9f7e1f96d155a/platform/chromium/vapi-common.js#L172 GV didn't want to add API for it so I took a stab at adding this to our fetch libs: #6314 (comment) @pocmo can you take a look since we looked at download stuff today :). I've time-boxed this and limited to base64 encoded URIs. The device and unit tests pass and the download works / can be tested here: https://jsfiddle.net/nue9rg0L/2/ Co-authored-by: Christian Sadilek <christian.sadilek@gmail.com>
Timed out |
|
bors retry |
Build succeeded |
With this we can fetch from data URIs and downloads "just work" (we don't require any special handling). So, e.g. this works now (which is also used by uBlock to save backups):
https://github.com/gorhill/uBlock/blob/08d370d32e648c2823e1bc31fcd9f7e1f96d155a/platform/chromium/vapi-common.js#L172
GV didn't want to add API for it so I took a stab at adding this to our fetch libs: #6314 (comment)
@pocmo can you take a look since we looked at download stuff today :). I've time-boxed this and limited to base64 encoded URIs. The device and unit tests pass and the download works / can be tested here:
https://jsfiddle.net/nue9rg0L/2/