The Free Software Media System - Server Backend & API
Remove duplicate code and use using to properly dispose the response stream
Claus Viumfb7de2f9669c
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.csindex 2232b3eebb..2e07281369 100644--- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs+++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs@@ -539,21 +539,10 @@ namespace Emby.Server.Implementations.HttpClientManagervar contentLength = GetContentLength(httpResponse);- if (contentLength.HasValue)- {- using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))- {- await httpResponse.GetResponseStream().CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);- }- }- else+ using (var stream = httpResponse.GetResponseStream())+ using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true)){- // We're not able to track progress- using (var stream = httpResponse.GetResponseStream())- using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))- {- await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);- }+ await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);}options.Progress.Report(100);