Add FollowRedirects option to downloader

Introduces a FollowRedirects property to UnitDownloaderOptions and its builder, allowing control over HTTP redirect behavior. Updates UnitDownloader to use this option, following redirects when enabled and reporting progress accordingly.
This commit is contained in:
qwsdcvghyu89
2025-11-16 01:11:22 +11:00
parent 6f37d217db
commit 580ceb8c3c
3 changed files with 20 additions and 2 deletions
+11 -2
View File
@@ -25,8 +25,17 @@ namespace Beam.Downloaders {
protected virtual async Task DownloadToStream(string url, int bufferSize, Stream destinationStream, IProgress<IDownloadReport> progress,
CancellationToken ct) {
var stream = await Client.GetStreamAsync(url, ct);
if (options.FollowRedirects) {
var response = await Client.GetAsync(url, ct); // automatically follows redirects
await response.Content.CopyToAsync(destinationStream, ct);
progress?.Report(new DownloadReport() {
BytesDownloaded = destinationStream.Length,
BytesRemaining = 0
});
return;
}
var stream = await Client.GetStreamAsync(url, ct); // does not follow redirects
byte[] buffer = new byte[bufferSize];
int inBuffer = 0;
long downloaded = 0;