use proper HttpClient DI

pull/3691/head
crobibero 4 years ago
parent 37496e958f
commit 7bb34fc9e7

@ -41,7 +41,7 @@ namespace Jellyfin.Api.Controllers
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
private readonly TranscodingJobHelper _transcodingJobHelper; private readonly TranscodingJobHelper _transcodingJobHelper;
private readonly HttpClient _httpClient; private readonly IHttpClientFactory _httpClientFactory;
private readonly TranscodingJobType _transcodingJobType = TranscodingJobType.Progressive; private readonly TranscodingJobType _transcodingJobType = TranscodingJobType.Progressive;
@ -61,7 +61,7 @@ namespace Jellyfin.Api.Controllers
/// <param name="configuration">Instance of the <see cref="IConfiguration"/> interface.</param> /// <param name="configuration">Instance of the <see cref="IConfiguration"/> interface.</param>
/// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param> /// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param>
/// <param name="transcodingJobHelper">The <see cref="TranscodingJobHelper"/> singleton.</param> /// <param name="transcodingJobHelper">The <see cref="TranscodingJobHelper"/> singleton.</param>
/// <param name="httpClient">Instance of the <see cref="HttpClient"/>.</param> /// <param name="httpClientFactory">Instance of the <see cref="IHttpClientFactory"/> interface.</param>
public AudioController( public AudioController(
IDlnaManager dlnaManager, IDlnaManager dlnaManager,
IUserManager userManger, IUserManager userManger,
@ -76,7 +76,7 @@ namespace Jellyfin.Api.Controllers
IConfiguration configuration, IConfiguration configuration,
IDeviceManager deviceManager, IDeviceManager deviceManager,
TranscodingJobHelper transcodingJobHelper, TranscodingJobHelper transcodingJobHelper,
HttpClient httpClient) IHttpClientFactory httpClientFactory)
{ {
_dlnaManager = dlnaManager; _dlnaManager = dlnaManager;
_authContext = authorizationContext; _authContext = authorizationContext;
@ -91,7 +91,7 @@ namespace Jellyfin.Api.Controllers
_configuration = configuration; _configuration = configuration;
_deviceManager = deviceManager; _deviceManager = deviceManager;
_transcodingJobHelper = transcodingJobHelper; _transcodingJobHelper = transcodingJobHelper;
_httpClient = httpClient; _httpClientFactory = httpClientFactory;
} }
/// <summary> /// <summary>
@ -295,7 +295,8 @@ namespace Jellyfin.Api.Controllers
{ {
StreamingHelpers.AddDlnaHeaders(state, Response.Headers, true, startTimeTicks, Request, _dlnaManager); StreamingHelpers.AddDlnaHeaders(state, Response.Headers, true, startTimeTicks, Request, _dlnaManager);
return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, isHeadRequest, this, _httpClient).ConfigureAwait(false); using var httpClient = _httpClientFactory.CreateClient();
return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, isHeadRequest, this, httpClient).ConfigureAwait(false);
} }
if (@static.HasValue && @static.Value && state.InputProtocol != MediaProtocol.File) if (@static.HasValue && @static.Value && state.InputProtocol != MediaProtocol.File)

@ -52,7 +52,7 @@ namespace Jellyfin.Api.Controllers
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly IDeviceManager _deviceManager; private readonly IDeviceManager _deviceManager;
private readonly TranscodingJobHelper _transcodingJobHelper; private readonly TranscodingJobHelper _transcodingJobHelper;
private readonly HttpClient _httpClient; private readonly IHttpClientFactory _httpClientFactory;
private readonly TranscodingJobType _transcodingJobType = TranscodingJobType.Progressive; private readonly TranscodingJobType _transcodingJobType = TranscodingJobType.Progressive;
@ -73,7 +73,7 @@ namespace Jellyfin.Api.Controllers
/// <param name="configuration">Instance of the <see cref="IConfiguration"/> interface.</param> /// <param name="configuration">Instance of the <see cref="IConfiguration"/> interface.</param>
/// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param> /// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param>
/// <param name="transcodingJobHelper">Instance of the <see cref="TranscodingJobHelper"/> class.</param> /// <param name="transcodingJobHelper">Instance of the <see cref="TranscodingJobHelper"/> class.</param>
/// <param name="httpClient">Instance of the <see cref="HttpClient"/> class.</param> /// <param name="httpClientFactory">Instance of the <see cref="IHttpClientFactory"/> interface.</param>
public VideosController( public VideosController(
ILibraryManager libraryManager, ILibraryManager libraryManager,
IUserManager userManager, IUserManager userManager,
@ -89,7 +89,7 @@ namespace Jellyfin.Api.Controllers
IConfiguration configuration, IConfiguration configuration,
IDeviceManager deviceManager, IDeviceManager deviceManager,
TranscodingJobHelper transcodingJobHelper, TranscodingJobHelper transcodingJobHelper,
HttpClient httpClient) IHttpClientFactory httpClientFactory)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_userManager = userManager; _userManager = userManager;
@ -105,7 +105,7 @@ namespace Jellyfin.Api.Controllers
_configuration = configuration; _configuration = configuration;
_deviceManager = deviceManager; _deviceManager = deviceManager;
_transcodingJobHelper = transcodingJobHelper; _transcodingJobHelper = transcodingJobHelper;
_httpClient = httpClient; _httpClientFactory = httpClientFactory;
} }
/// <summary> /// <summary>
@ -465,7 +465,8 @@ namespace Jellyfin.Api.Controllers
{ {
StreamingHelpers.AddDlnaHeaders(state, Response.Headers, true, startTimeTicks, Request, _dlnaManager); StreamingHelpers.AddDlnaHeaders(state, Response.Headers, true, startTimeTicks, Request, _dlnaManager);
return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, isHeadRequest, this, _httpClient).ConfigureAwait(false); using var httpClient = _httpClientFactory.CreateClient();
return await FileStreamResponseHelpers.GetStaticRemoteStreamResult(state, isHeadRequest, this, httpClient).ConfigureAwait(false);
} }
if (@static.HasValue && @static.Value && state.InputProtocol != MediaProtocol.File) if (@static.HasValue && @static.Value && state.InputProtocol != MediaProtocol.File)

@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="3.1.6" /> <PackageReference Include="Microsoft.AspNetCore.Authorization" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="5.3.3" /> <PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="5.3.3" />
</ItemGroup> </ItemGroup>

@ -1,3 +1,4 @@
using System.Net.Http;
using Jellyfin.Server.Extensions; using Jellyfin.Server.Extensions;
using Jellyfin.Server.Middleware; using Jellyfin.Server.Middleware;
using Jellyfin.Server.Models; using Jellyfin.Server.Models;
@ -43,6 +44,7 @@ namespace Jellyfin.Server
services.AddCustomAuthentication(); services.AddCustomAuthentication();
services.AddJellyfinApiAuthorization(); services.AddJellyfinApiAuthorization();
services.AddHttpClient();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save