diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index bbd7166e68..8e46c73eee 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Net; +using System.Net.Http; using System.Net.Mime; using System.Threading; using System.Threading.Tasks; @@ -44,7 +45,7 @@ namespace MediaBrowser.Providers.Manager { private readonly object _refreshQueueLock = new object(); private readonly ILogger _logger; - private readonly IHttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly ILibraryMonitor _libraryMonitor; private readonly IFileSystem _fileSystem; private readonly IServerApplicationPaths _appPaths; @@ -66,7 +67,7 @@ namespace MediaBrowser.Providers.Manager /// /// Initializes a new instance of the class. /// - /// The Http client. + /// The Http client factory. /// The subtitle manager. /// The configuration manager. /// The library monitor. @@ -75,7 +76,7 @@ namespace MediaBrowser.Providers.Manager /// The server application paths. /// The library manager. public ProviderManager( - IHttpClient httpClient, + IHttpClientFactory httpClientFactory, ISubtitleManager subtitleManager, IServerConfigurationManager configurationManager, ILibraryMonitor libraryMonitor, @@ -85,7 +86,7 @@ namespace MediaBrowser.Providers.Manager ILibraryManager libraryManager) { _logger = logger; - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _configurationManager = configurationManager; _libraryMonitor = libraryMonitor; _fileSystem = fileSystem; @@ -155,25 +156,23 @@ namespace MediaBrowser.Providers.Manager /// public async Task SaveImage(BaseItem item, string url, ImageType type, int? imageIndex, CancellationToken cancellationToken) { - using var response = await _httpClient.GetResponse(new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url, - BufferContent = false - }).ConfigureAwait(false); + var httpClient = _httpClientFactory.CreateClient(); + using var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false); + + var contentType = response.Content.Headers.ContentType.MediaType; // Workaround for tvheadend channel icons // TODO: Isolate this hack into the tvh plugin - if (string.IsNullOrEmpty(response.ContentType)) + if (string.IsNullOrEmpty(contentType)) { if (url.IndexOf("/imagecache/", StringComparison.OrdinalIgnoreCase) != -1) { - response.ContentType = "image/png"; + contentType = "image/png"; } } // thetvdb will sometimes serve a rubbish 404 html page with a 200 OK code, because reasons... - if (response.ContentType.Equals(MediaTypeNames.Text.Html, StringComparison.OrdinalIgnoreCase)) + if (contentType.Equals(MediaTypeNames.Text.Html, StringComparison.OrdinalIgnoreCase)) { throw new HttpException("Invalid image received.") { @@ -181,7 +180,13 @@ namespace MediaBrowser.Providers.Manager }; } - await SaveImage(item, response.Content, response.ContentType, type, imageIndex, cancellationToken).ConfigureAwait(false); + await SaveImage( + item, + await response.Content.ReadAsStreamAsync().ConfigureAwait(false), + contentType, + type, + imageIndex, + cancellationToken).ConfigureAwait(false); } ///