diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-10-02 13:05:13 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-10-02 13:05:13 -0400 |
| commit | bb4c918bf8403b2058f5fbbf2c0b1943b4b5f327 (patch) | |
| tree | 1c14879511e69a5a989ccf95f2de491f5b3eb9d2 | |
| parent | 9f8a1b30a1ecec0af3c48bcb30e035938f93218c (diff) | |
refactor http client factory for mono
| -rw-r--r-- | MediaBrowser.Common.Implementations/BaseApplicationHost.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs | 19 | ||||
| -rw-r--r-- | MediaBrowser.Mono.userprefs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj | 2 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mono/Native/HttpClientFactory.cs | 24 | ||||
| -rw-r--r-- | MediaBrowser.Server.Mono/Native/HttpMessageHandlerFactory.cs | 24 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/ApplicationHost.cs | 9 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj | 2 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/Native/HttpClientFactory.cs (renamed from MediaBrowser.ServerApplication/Native/HttpMessageHandlerFactory.cs) | 18 |
9 files changed, 52 insertions, 54 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 4c2d5d599..4a614f42d 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -332,7 +332,7 @@ namespace MediaBrowser.Common.Implementations RegisterSingleInstance(TaskManager); - HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, GetHttpMessageHandler); + HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, CreateHttpClient); RegisterSingleInstance(HttpClient); NetworkManager = new NetworkManager(); @@ -352,7 +352,7 @@ namespace MediaBrowser.Common.Implementations }); } - protected abstract HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression); + protected abstract HttpClient CreateHttpClient(bool enableHttpCompression); /// <summary> /// Gets a list of types within an assembly diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 3a626000f..412c69509 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -31,21 +31,22 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// </summary> 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> - /// Initializes a new instance of the <see cref="HttpClientManager" /> class. + /// Initializes a new instance of the <see cref="HttpClientManager"/> class. /// </summary> - /// <param name="appPaths">The kernel.</param> + /// <param name="appPaths">The app paths.</param> /// <param name="logger">The logger.</param> + /// <param name="getHttpClientHandler">The get HTTP client handler.</param> /// <exception cref="System.ArgumentNullException"> /// appPaths /// or /// logger /// </exception> - public HttpClientManager(IApplicationPaths appPaths, ILogger logger, GetHttpMessageHandler getHttpMessageHandler) + public HttpClientManager(IApplicationPaths appPaths, ILogger logger, GetHttpClientHandler getHttpClientHandler) { if (appPaths == null) { @@ -57,7 +58,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } _logger = logger; - _getHttpMessageHandler = getHttpMessageHandler; + _getHttpClientHandler = getHttpClientHandler; _appPaths = appPaths; } @@ -90,10 +91,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager { client = new HttpClientInfo { - HttpClient = new HttpClient(_getHttpMessageHandler(enableHttpCompression)) - { - Timeout = TimeSpan.FromSeconds(20) - } + + HttpClient = _getHttpClientHandler(enableHttpCompression) }; _httpClients.TryAdd(key, client); } diff --git a/MediaBrowser.Mono.userprefs b/MediaBrowser.Mono.userprefs index 4766c133a..6275e3545 100644 --- a/MediaBrowser.Mono.userprefs +++ b/MediaBrowser.Mono.userprefs @@ -1,11 +1,11 @@ <Properties> <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> <File FileName="MediaBrowser.Server.Mono\app.config" 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\Native\HttpMessageHandlerFactory.cs" Line="20" Column="99" /> + <File FileName="MediaBrowser.Server.Mono\Native\HttpClientFactory.cs" Line="6" Column="15" /> </Files> </MonoDevelop.Ide.Workbench> <MonoDevelop.Ide.DebuggingService.Breakpoints> diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index af3d72d69..4fd158f4e 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -81,9 +81,9 @@ <Compile Include="..\MediaBrowser.ServerApplication\ApplicationHost.cs"> <Link>ApplicationHost.cs</Link> </Compile> - <Compile Include="Native\HttpMessageHandlerFactory.cs" /> <Compile Include="Native\Assemblies.cs" /> <Compile Include="Native\NativeApp.cs" /> + <Compile Include="Native\HttpClientFactory.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> diff --git a/MediaBrowser.Server.Mono/Native/HttpClientFactory.cs b/MediaBrowser.Server.Mono/Native/HttpClientFactory.cs new file mode 100644 index 000000000..0fceab060 --- /dev/null +++ b/MediaBrowser.Server.Mono/Native/HttpClientFactory.cs @@ -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) + }; + } + } +} diff --git a/MediaBrowser.Server.Mono/Native/HttpMessageHandlerFactory.cs b/MediaBrowser.Server.Mono/Native/HttpMessageHandlerFactory.cs deleted file mode 100644 index 627218a01..000000000 --- a/MediaBrowser.Server.Mono/Native/HttpMessageHandlerFactory.cs +++ /dev/null @@ -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 - }; - } - } -} diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 9e13e548a..a624fc18c 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -672,14 +672,9 @@ namespace MediaBrowser.ServerApplication OnApplicationUpdated(package.version); } - /// <summary> - /// 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) + protected override HttpClient CreateHttpClient(bool enableHttpCompression) { - return HttpMessageHandlerFactory.GetHttpMessageHandler(enableHttpCompression); + return HttpClientFactory.GetHttpClient(enableHttpCompression); } protected override void ConfigureAutoRunAtStartup(bool autorun) diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index cbcb3ac25..efc3adf56 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -188,7 +188,7 @@ <Compile Include="EntryPoints\StartupWizard.cs" /> <Compile Include="FFMpeg\FFMpegInfo.cs" /> <Compile Include="Native\Assemblies.cs" /> - <Compile Include="Native\HttpMessageHandlerFactory.cs" /> + <Compile Include="Native\HttpClientFactory.cs" /> <Compile Include="Native\NativeApp.cs" /> <Compile Include="Native\ServerAuthorization.cs" /> <Compile Include="Native\Autorun.cs" /> diff --git a/MediaBrowser.ServerApplication/Native/HttpMessageHandlerFactory.cs b/MediaBrowser.ServerApplication/Native/HttpClientFactory.cs index 4bbcc9ea0..57f00ba03 100644 --- a/MediaBrowser.ServerApplication/Native/HttpMessageHandlerFactory.cs +++ b/MediaBrowser.ServerApplication/Native/HttpClientFactory.cs @@ -1,25 +1,29 @@ -using System.Net; +using System; +using System.Net; using System.Net.Cache; using System.Net.Http; namespace MediaBrowser.ServerApplication.Native { /// <summary> - /// Class HttpMessageHandlerFactory + /// Class HttpClientFactory /// </summary> - public static class HttpMessageHandlerFactory + public static class HttpClientFactory { /// <summary> - /// Gets the HTTP message handler. + /// Gets the HTTP client. /// </summary> /// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param> - /// <returns>HttpMessageHandler.</returns> - public static HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression) + /// <returns>HttpClient.</returns> + public static HttpClient GetHttpClient(bool enableHttpCompression) { - return new WebRequestHandler + return new HttpClient(new WebRequestHandler { CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate), AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None + }) + { + Timeout = TimeSpan.FromSeconds(20) }; } } |
