mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
migrate to IHttpClientFactory in XmlTvListingsProvider
This commit is contained in:
parent
652e688cc1
commit
97cc3d54bb
@ -25,20 +25,20 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
public class XmlTvListingsProvider : IListingsProvider
|
public class XmlTvListingsProvider : IListingsProvider
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly ILogger<XmlTvListingsProvider> _logger;
|
private readonly ILogger<XmlTvListingsProvider> _logger;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IZipClient _zipClient;
|
private readonly IZipClient _zipClient;
|
||||||
|
|
||||||
public XmlTvListingsProvider(
|
public XmlTvListingsProvider(
|
||||||
IServerConfigurationManager config,
|
IServerConfigurationManager config,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
ILogger<XmlTvListingsProvider> logger,
|
ILogger<XmlTvListingsProvider> logger,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IZipClient zipClient)
|
IZipClient zipClient)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_zipClient = zipClient;
|
_zipClient = zipClient;
|
||||||
@ -78,29 +78,12 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
|
Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
|
||||||
|
|
||||||
using (var res = await _httpClient.SendAsync(
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(path, cancellationToken).ConfigureAwait(false);
|
||||||
new HttpRequestOptions
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
{
|
await using (var fileStream = new FileStream(cacheFile, FileMode.CreateNew))
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
Url = path,
|
|
||||||
DecompressionMethod = CompressionMethods.Gzip,
|
|
||||||
},
|
|
||||||
HttpMethod.Get).ConfigureAwait(false))
|
|
||||||
using (var stream = res.Content)
|
|
||||||
using (var fileStream = new FileStream(cacheFile, FileMode.CreateNew))
|
|
||||||
{
|
|
||||||
if (res.ContentHeaders.ContentEncoding.Contains("gzip"))
|
|
||||||
{
|
|
||||||
using (var gzStream = new GZipStream(stream, CompressionMode.Decompress))
|
|
||||||
{
|
|
||||||
await gzStream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
|
await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return UnzipIfNeeded(path, cacheFile);
|
return UnzipIfNeeded(path, cacheFile);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user