diff --git a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs index 34b0d4e..0c35871 100644 --- a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs +++ b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs @@ -705,7 +705,7 @@ namespace Roadie.Library.Engines { var sw2 = Stopwatch.StartNew(); var imageBag = new ConcurrentBag(); - var i = artistImageUrls.Select(async url => imageBag.Add(await WebHelper.GetImageFromUrlAsync(url).ConfigureAwait(false))); + var i = artistImageUrls.Select(async url => imageBag.Add(await WebHelper.GetImageFromUrlAsync(HttpClientFactory, url).ConfigureAwait(false))); await Task.WhenAll(i).ConfigureAwait(false); result.Images = imageBag.Where(x => x?.Bytes != null) .GroupBy(x => x.Signature) diff --git a/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs b/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs index 357ae2c..10de8fe 100644 --- a/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs +++ b/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs @@ -915,7 +915,7 @@ namespace Roadie.Library.Engines { var sw2 = Stopwatch.StartNew(); var imageBag = new ConcurrentBag(); - var i = releaseImageUrls.Select(async url => imageBag.Add(await WebHelper.GetImageFromUrlAsync(url).ConfigureAwait(false))); + var i = releaseImageUrls.Select(async url => imageBag.Add(await WebHelper.GetImageFromUrlAsync(HttpClientFactory, url).ConfigureAwait(false))); await Task.WhenAll(i).ConfigureAwait(false); releaseImages = imageBag.Where(x => x?.Bytes != null) .GroupBy(x => x.Signature) diff --git a/Roadie.Api.Library/Utility/WebHelper.cs b/Roadie.Api.Library/Utility/WebHelper.cs index b81debe..3f1df50 100644 --- a/Roadie.Api.Library/Utility/WebHelper.cs +++ b/Roadie.Api.Library/Utility/WebHelper.cs @@ -24,6 +24,7 @@ namespace Roadie.Library.Utility { var client = httpclientFactory.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); + request.Headers.Add("User-Agent", UserAgent); var response = await client.SendAsync(request).ConfigureAwait(false); if(response.IsSuccessStatusCode) { @@ -58,15 +59,18 @@ namespace Roadie.Library.Utility return null; } - public static async Task GetImageFromUrlAsync(string url) + public static async Task GetImageFromUrlAsync(IHttpClientFactory httpclientFactory, string url) { byte[] imageBytes = null; try { - using (var webClient = new WebClient()) + var client = httpclientFactory.CreateClient(); + var request = new HttpRequestMessage(HttpMethod.Get, url); + request.Headers.Add("User-Agent", UserAgent); + var response = await client.SendAsync(request).ConfigureAwait(false); + if (response.IsSuccessStatusCode) { - webClient.Headers.Add("user-agent", UserAgent); - imageBytes = await webClient.DownloadDataTaskAsync(new Uri(url)).ConfigureAwait(false); + imageBytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); } } catch