Add 'ETag header' option for HTML and direct APK links (#2221) - needs testing

This commit is contained in:
Imran Remtulla
2025-04-05 14:32:26 -04:00
parent 2aa91ed535
commit 94ab83ff75
3 changed files with 52 additions and 17 deletions

View File

@@ -220,6 +220,19 @@ Future<String> checkPartialDownloadHash(String url, int bytesToGrab,
return hashListOfLists(bytes);
}
Future<String?> checkETagHeader(String url,
{Map<String, String>? headers, bool allowInsecure = false}) async {
// Send the initial request but cancel it as soon as you have the headers
var reqHeaders = headers ?? {};
var req = Request('GET', Uri.parse(url));
req.headers.addAll(reqHeaders);
var client = IOClient(createHttpClient(allowInsecure));
StreamedResponse response = await client.send(req);
var resHeaders = response.headers;
client.close();
return resHeaders[HttpHeaders.etagHeader];
}
Future<File> downloadFile(String url, String fileName, bool fileNameHasExt,
Function? onProgress, String destDir,
{bool useExisting = true,