Fixed: Resource leakage inside HttpClient.

This commit is contained in:
Leonardo Galli 2018-12-01 16:55:26 +01:00
parent df18c34878
commit c83995adc1
1 changed files with 7 additions and 5 deletions

View File

@ -226,12 +226,14 @@ namespace NzbDrone.Common.Http
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName); _logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
var stopWatch = Stopwatch.StartNew(); var stopWatch = Stopwatch.StartNew();
var webClient = new GZipWebClient(); using (var webClient = new GZipWebClient())
{
webClient.Headers.Add(HttpRequestHeader.UserAgent, UserAgentBuilder.UserAgent); webClient.Headers.Add(HttpRequestHeader.UserAgent, UserAgentBuilder.UserAgent);
webClient.DownloadFile(url, fileName); webClient.DownloadFile(url, fileName);
stopWatch.Stop(); stopWatch.Stop();
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds); _logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
} }
}
catch (WebException e) catch (WebException e)
{ {
_logger.Warn("Failed to get response from: {0} {1}", url, e.Message); _logger.Warn("Failed to get response from: {0} {1}", url, e.Message);