caller of GetAsStreamAsync() should handle disposal of Stream, HttpResponseMessage doesn't necessarily need disposing itself

This commit is contained in:
Collin M. Barrett 2019-07-12 15:50:18 -05:00
parent 679cf67107
commit 9eb27bd787

View file

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
@ -27,9 +28,10 @@ public ListRepository(HttpClient httpClient, ILogger<ListRepository> logger)
_logger = logger;
}
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")]
public async Task<Stream> GetAsStreamAsync(Uri url, CancellationToken cancellationToken)
{
using var response = await _httpClient.GetAsync(url, cancellationToken);
var response = await _httpClient.GetAsync(url, cancellationToken);
if (response.IsSuccessStatusCode)
return await response.Content.ReadAsStreamAsync();
_logger.LogError($"Error downloading list from {url}. {response.StatusCode}");