mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05: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,26 +1299,18 @@ 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,
 | 
					                await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
 | 
				
			||||||
                        BufferContent = false,
 | 
					                var result = await System.Text.Json.JsonSerializer.DeserializeAsync<string>(stream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(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);
 | 
					                var valid = string.Equals(Name, result, StringComparison.OrdinalIgnoreCase);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                _validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid);
 | 
					                _validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid);
 | 
				
			||||||
                Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid);
 | 
					                Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid);
 | 
				
			||||||
                return valid;
 | 
					                return valid;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            catch (OperationCanceledException)
 | 
					            catch (OperationCanceledException)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, "Cancelled");
 | 
					                Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, "Cancelled");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user