mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
refactor http client factory for mono
This commit is contained in:
parent
9f8a1b30a1
commit
bb4c918bf8
@ -332,7 +332,7 @@ namespace MediaBrowser.Common.Implementations
|
|||||||
|
|
||||||
RegisterSingleInstance(TaskManager);
|
RegisterSingleInstance(TaskManager);
|
||||||
|
|
||||||
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, GetHttpMessageHandler);
|
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, CreateHttpClient);
|
||||||
RegisterSingleInstance(HttpClient);
|
RegisterSingleInstance(HttpClient);
|
||||||
|
|
||||||
NetworkManager = new NetworkManager();
|
NetworkManager = new NetworkManager();
|
||||||
@ -352,7 +352,7 @@ namespace MediaBrowser.Common.Implementations
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression);
|
protected abstract HttpClient CreateHttpClient(bool enableHttpCompression);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list of types within an assembly
|
/// Gets a list of types within an assembly
|
||||||
|
@ -31,21 +31,22 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
|
||||||
public delegate HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression);
|
public delegate HttpClient GetHttpClientHandler(bool enableHttpCompression);
|
||||||
|
|
||||||
private readonly GetHttpMessageHandler _getHttpMessageHandler;
|
private readonly GetHttpClientHandler _getHttpClientHandler;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="HttpClientManager" /> class.
|
/// Initializes a new instance of the <see cref="HttpClientManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="appPaths">The kernel.</param>
|
/// <param name="appPaths">The app paths.</param>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
|
/// <param name="getHttpClientHandler">The get HTTP client handler.</param>
|
||||||
/// <exception cref="System.ArgumentNullException">
|
/// <exception cref="System.ArgumentNullException">
|
||||||
/// appPaths
|
/// appPaths
|
||||||
/// or
|
/// or
|
||||||
/// logger
|
/// logger
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public HttpClientManager(IApplicationPaths appPaths, ILogger logger, GetHttpMessageHandler getHttpMessageHandler)
|
public HttpClientManager(IApplicationPaths appPaths, ILogger logger, GetHttpClientHandler getHttpClientHandler)
|
||||||
{
|
{
|
||||||
if (appPaths == null)
|
if (appPaths == null)
|
||||||
{
|
{
|
||||||
@ -57,7 +58,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_getHttpMessageHandler = getHttpMessageHandler;
|
_getHttpClientHandler = getHttpClientHandler;
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,10 +91,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
|||||||
{
|
{
|
||||||
client = new HttpClientInfo
|
client = new HttpClientInfo
|
||||||
{
|
{
|
||||||
HttpClient = new HttpClient(_getHttpMessageHandler(enableHttpCompression))
|
|
||||||
{
|
HttpClient = _getHttpClientHandler(enableHttpCompression)
|
||||||
Timeout = TimeSpan.FromSeconds(20)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
_httpClients.TryAdd(key, client);
|
_httpClients.TryAdd(key, client);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release|x86" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release|x86" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\Native\HttpMessageHandlerFactory.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\Native\HttpClientFactory.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="MediaBrowser.Server.Mono\app.config" Line="1" Column="1" />
|
<File FileName="MediaBrowser.Server.Mono\app.config" Line="1" Column="1" />
|
||||||
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="1" Column="1" />
|
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="1" Column="1" />
|
||||||
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
|
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
|
||||||
<File FileName="MediaBrowser.Server.Mono\Native\HttpMessageHandlerFactory.cs" Line="20" Column="99" />
|
<File FileName="MediaBrowser.Server.Mono\Native\HttpClientFactory.cs" Line="6" Column="15" />
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
@ -81,9 +81,9 @@
|
|||||||
<Compile Include="..\MediaBrowser.ServerApplication\ApplicationHost.cs">
|
<Compile Include="..\MediaBrowser.ServerApplication\ApplicationHost.cs">
|
||||||
<Link>ApplicationHost.cs</Link>
|
<Link>ApplicationHost.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Native\HttpMessageHandlerFactory.cs" />
|
|
||||||
<Compile Include="Native\Assemblies.cs" />
|
<Compile Include="Native\Assemblies.cs" />
|
||||||
<Compile Include="Native\NativeApp.cs" />
|
<Compile Include="Native\NativeApp.cs" />
|
||||||
|
<Compile Include="Native\HttpClientFactory.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
24
MediaBrowser.Server.Mono/Native/HttpClientFactory.cs
Normal file
24
MediaBrowser.Server.Mono/Native/HttpClientFactory.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
|
namespace MediaBrowser.ServerApplication.Native
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class HttpClientFactory
|
||||||
|
/// </summary>
|
||||||
|
public static class HttpClientFactory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HTTP client.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
|
||||||
|
/// <returns>HttpClient.</returns>
|
||||||
|
public static HttpClient GetHttpClient(bool enableHttpCompression)
|
||||||
|
{
|
||||||
|
return new HttpClient()
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromSeconds(20)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
|
|
||||||
namespace MediaBrowser.ServerApplication.Native
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Class HttpMessageHandlerFactory
|
|
||||||
/// </summary>
|
|
||||||
public static class HttpMessageHandlerFactory
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the HTTP message handler.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
|
|
||||||
/// <returns>HttpMessageHandler.</returns>
|
|
||||||
public static HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
|
|
||||||
{
|
|
||||||
return new HttpClientHandler
|
|
||||||
{
|
|
||||||
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -672,14 +672,9 @@ namespace MediaBrowser.ServerApplication
|
|||||||
OnApplicationUpdated(package.version);
|
OnApplicationUpdated(package.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
protected override HttpClient CreateHttpClient(bool enableHttpCompression)
|
||||||
/// Gets the HTTP message handler.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
|
|
||||||
/// <returns>HttpMessageHandler.</returns>
|
|
||||||
protected override HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
|
|
||||||
{
|
{
|
||||||
return HttpMessageHandlerFactory.GetHttpMessageHandler(enableHttpCompression);
|
return HttpClientFactory.GetHttpClient(enableHttpCompression);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ConfigureAutoRunAtStartup(bool autorun)
|
protected override void ConfigureAutoRunAtStartup(bool autorun)
|
||||||
|
@ -188,7 +188,7 @@
|
|||||||
<Compile Include="EntryPoints\StartupWizard.cs" />
|
<Compile Include="EntryPoints\StartupWizard.cs" />
|
||||||
<Compile Include="FFMpeg\FFMpegInfo.cs" />
|
<Compile Include="FFMpeg\FFMpegInfo.cs" />
|
||||||
<Compile Include="Native\Assemblies.cs" />
|
<Compile Include="Native\Assemblies.cs" />
|
||||||
<Compile Include="Native\HttpMessageHandlerFactory.cs" />
|
<Compile Include="Native\HttpClientFactory.cs" />
|
||||||
<Compile Include="Native\NativeApp.cs" />
|
<Compile Include="Native\NativeApp.cs" />
|
||||||
<Compile Include="Native\ServerAuthorization.cs" />
|
<Compile Include="Native\ServerAuthorization.cs" />
|
||||||
<Compile Include="Native\Autorun.cs" />
|
<Compile Include="Native\Autorun.cs" />
|
||||||
|
@ -1,25 +1,29 @@
|
|||||||
using System.Net;
|
using System;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Cache;
|
using System.Net.Cache;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace MediaBrowser.ServerApplication.Native
|
namespace MediaBrowser.ServerApplication.Native
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class HttpMessageHandlerFactory
|
/// Class HttpClientFactory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class HttpMessageHandlerFactory
|
public static class HttpClientFactory
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the HTTP message handler.
|
/// Gets the HTTP client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
|
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
|
||||||
/// <returns>HttpMessageHandler.</returns>
|
/// <returns>HttpClient.</returns>
|
||||||
public static HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
|
public static HttpClient GetHttpClient(bool enableHttpCompression)
|
||||||
{
|
{
|
||||||
return new WebRequestHandler
|
return new HttpClient(new WebRequestHandler
|
||||||
{
|
{
|
||||||
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
|
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
|
||||||
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
|
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
|
||||||
|
})
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromSeconds(20)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user