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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user