migrate to IHttpClientFactory in SharedHttpStream

pull/4030/head
crobibero 4 years ago
parent 96fdee38cb
commit af9ebef577

@ -21,7 +21,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{ {
public class SharedHttpStream : LiveStream, IDirectStreamProvider public class SharedHttpStream : LiveStream, IDirectStreamProvider
{ {
private readonly IHttpClient _httpClient; private readonly IHttpClientFactory _httpClientFactory;
private readonly IServerApplicationHost _appHost; private readonly IServerApplicationHost _appHost;
public SharedHttpStream( public SharedHttpStream(
@ -29,14 +29,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
TunerHostInfo tunerHostInfo, TunerHostInfo tunerHostInfo,
string originalStreamId, string originalStreamId,
IFileSystem fileSystem, IFileSystem fileSystem,
IHttpClient httpClient, IHttpClientFactory httpClientFactory,
ILogger logger, ILogger logger,
IConfigurationManager configurationManager, IConfigurationManager configurationManager,
IServerApplicationHost appHost, IServerApplicationHost appHost,
IStreamHelper streamHelper) IStreamHelper streamHelper)
: base(mediaSource, tunerHostInfo, fileSystem, logger, configurationManager, streamHelper) : base(mediaSource, tunerHostInfo, fileSystem, logger, configurationManager, streamHelper)
{ {
_httpClient = httpClient; _httpClientFactory = httpClientFactory;
_appHost = appHost; _appHost = appHost;
OriginalStreamId = originalStreamId; OriginalStreamId = originalStreamId;
EnableStreamSharing = true; EnableStreamSharing = true;
@ -68,12 +68,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
httpRequestOptions.RequestHeaders[header.Key] = header.Value; httpRequestOptions.RequestHeaders[header.Key] = header.Value;
} }
var response = await _httpClient.SendAsync(httpRequestOptions, HttpMethod.Get).ConfigureAwait(false); using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetAsync(url, CancellationToken.None)
.ConfigureAwait(false);
var extension = "ts"; var extension = "ts";
var requiresRemux = false; var requiresRemux = false;
var contentType = response.ContentType ?? string.Empty; var contentType = response.Content.Headers.ContentType.ToString();
if (contentType.IndexOf("matroska", StringComparison.OrdinalIgnoreCase) != -1) if (contentType.IndexOf("matroska", StringComparison.OrdinalIgnoreCase) != -1)
{ {
requiresRemux = true; requiresRemux = true;
@ -132,7 +134,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
} }
} }
private Task StartStreaming(HttpResponseInfo response, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken) private Task StartStreaming(HttpResponseMessage response, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
{ {
return Task.Run(async () => return Task.Run(async () =>
{ {
@ -140,8 +142,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{ {
Logger.LogInformation("Beginning {0} stream to {1}", GetType().Name, TempFilePath); Logger.LogInformation("Beginning {0} stream to {1}", GetType().Name, TempFilePath);
using (response) using (response)
using (var stream = response.Content) await using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
using (var fileStream = new FileStream(TempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read)) await using (var fileStream = new FileStream(TempFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
{ {
await StreamHelper.CopyToAsync( await StreamHelper.CopyToAsync(
stream, stream,

Loading…
Cancel
Save