mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-09 15:20:34 +02:00
migrate to IHttpClientFactory in ApplicationHost
This commit is contained in:
parent
533b981668
commit
6d19adbecf
|
@ -49,6 +49,7 @@ using Jellyfin.Api.Helpers;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Events;
|
using MediaBrowser.Common.Events;
|
||||||
|
using MediaBrowser.Common.Json;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Common.Updates;
|
using MediaBrowser.Common.Updates;
|
||||||
|
@ -123,7 +124,7 @@ namespace Emby.Server.Implementations
|
||||||
private IMediaEncoder _mediaEncoder;
|
private IMediaEncoder _mediaEncoder;
|
||||||
private ISessionManager _sessionManager;
|
private ISessionManager _sessionManager;
|
||||||
private IHttpServer _httpServer;
|
private IHttpServer _httpServer;
|
||||||
private IHttpClient _httpClient;
|
private IHttpClientFactory _httpClientFactory;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this instance can self restart.
|
/// Gets a value indicating whether this instance can self restart.
|
||||||
|
@ -653,7 +654,7 @@ namespace Emby.Server.Implementations
|
||||||
_mediaEncoder = Resolve<IMediaEncoder>();
|
_mediaEncoder = Resolve<IMediaEncoder>();
|
||||||
_sessionManager = Resolve<ISessionManager>();
|
_sessionManager = Resolve<ISessionManager>();
|
||||||
_httpServer = Resolve<IHttpServer>();
|
_httpServer = Resolve<IHttpServer>();
|
||||||
_httpClient = Resolve<IHttpClient>();
|
_httpClientFactory = Resolve<IHttpClientFactory>();
|
||||||
|
|
||||||
((AuthenticationRepository)Resolve<IAuthenticationRepository>()).Initialize();
|
((AuthenticationRepository)Resolve<IAuthenticationRepository>()).Initialize();
|
||||||
|
|
||||||
|
@ -1298,25 +1299,17 @@ namespace Emby.Server.Implementations
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var response = await _httpClient.SendAsync(
|
using var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
new HttpRequestOptions
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
||||||
{
|
.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||||
Url = apiUrl,
|
|
||||||
LogErrorResponseBody = false,
|
|
||||||
BufferContent = false,
|
|
||||||
CancellationToken = cancellationToken
|
|
||||||
}, HttpMethod.Post).ConfigureAwait(false))
|
|
||||||
{
|
|
||||||
using (var reader = new StreamReader(response.Content))
|
|
||||||
{
|
|
||||||
var result = await reader.ReadToEndAsync().ConfigureAwait(false);
|
|
||||||
var valid = string.Equals(Name, result, StringComparison.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
_validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid);
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid);
|
var result = await System.Text.Json.JsonSerializer.DeserializeAsync<string>(stream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
return valid;
|
var valid = string.Equals(Name, result, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
|
||||||
}
|
_validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid);
|
||||||
|
Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid);
|
||||||
|
return valid;
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue