Skip to content

Commit ff61d21

Browse files
committed
Add support for HTTP range requests in DownloadTask
Modified DownloadTask to use HttpRequestMessage with Range headers when resuming downloads. This enables partial downloads to continue from where they left off, improving reliability for interrupted downloads.
1 parent 0127ada commit ff61d21

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/c#/GeneralUpdate.Common/Download/DownloadTask.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Net.Http;
5+
using System.Net.Http.Headers;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using GeneralUpdate.Common.Shared;
@@ -54,7 +55,14 @@ private async Task DownloadFileRangeAsync(string url, string path)
5455
{
5556
var tempPath = path + ".temp";
5657
var startPos = CheckFile(tempPath);
57-
using var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
58+
59+
var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
60+
if (startPos > 0)
61+
{
62+
requestMessage.Headers.Range = new RangeHeaderValue(startPos, null);
63+
}
64+
65+
using var response = await _httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead);
5866
if (!response.IsSuccessStatusCode)
5967
throw new HttpRequestException($"Failed to download file: {response.ReasonPhrase}");
6068

0 commit comments

Comments
 (0)