also looking at this
fix(mobile): preserve native editing, navigation, and durable media requests
#369
36 files
+864
-185
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -50,11 +50,11 @@ class CraftNativeResumableDownloadTest { | ||
| 50 | 50 | else -> 200 |
| 51 | 51 | } |
| 52 | 52 | val bytes = when (code) { |
| 53 | 206 -> payload.copyOfRange(start!!, payload.size) | |
| 53 | 206 -> payload.copyOfRange(start ?: 0, payload.size) | |
| 54 | 54 | 200 -> payload |
| 55 | 55 | else -> byteArrayOf() |
| 56 | 56 | } |
| 57 | val contentRange = if (code == 206) "Content-Range: bytes $start-${payload.size - 1}/${payload.size}\r\n" else "" | |
| 57 | val contentRange = if (code == 206 && start != null) "Content-Range: bytes $start-${payload.size - 1}/${payload.size}\r\n" else "" | |
| 58 | 58 | val headers = "HTTP/1.1 $code Test\r\nContent-Length: ${bytes.size}\r\n${contentRange}Connection: close\r\n\r\n" |
| 59 | 59 | socket.getOutputStream().write(headers.toByteArray(Charsets.US_ASCII) + bytes) |
| 60 | 60 | } |
| @@ -126,6 +126,14 @@ class CraftNativeResumableDownloadTest { | ||
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | @Test | |
| 130 | fun refusesAnUnsolicitedPartialResponseWithoutRetryingIt() = part { file -> | |
| 131 | serve(status = 206) { address, _ -> | |
| 132 | assertEquals(CraftResumableDownload.Fetched.Refused(206), CraftResumableDownload().fetch(address, emptyMap(), file) { false }) | |
| 133 | assertFalse(file.exists()) | |
| 134 | } | |
| 135 | } | |
| 136 | ||
| 129 | 137 | @Test |
| 130 | 138 | fun refusesAnEmptyResponseWithoutRetainingAnUnresumablePart() = part { file -> |
| 131 | 139 | serve(payload = byteArrayOf()) { address, _ -> |
| @@ -1452,7 +1452,7 @@ internal class CraftResumableDownload( | ||
| 1452 | 1452 | val resumed = status == 206 && have > 0 && rangeStart(connection.getHeaderField("Content-Range")) == have |
| 1453 | 1453 | if (status == 416 || (status == 206 && !resumed)) { |
| 1454 | 1454 | part.delete() |
| 1455 | return Fetched.Restart | |
| 1455 | return if (have > 0) Fetched.Restart else Fetched.Refused(status) | |
| 1456 | 1456 | } |
| 1457 | 1457 | if (status != 200 && !resumed) { |
| 1458 | 1458 | part.delete() |