fully removed System.Net.HttpWebRequest dependency

This commit is contained in:
Luke Pulverenti 2013-08-28 16:12:58 -04:00
parent ac802322de
commit 528100ab31
6 changed files with 26 additions and 13 deletions

View File

@ -19,6 +19,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -272,7 +273,7 @@ namespace MediaBrowser.Common.Implementations
RegisterSingleInstance(TaskManager); RegisterSingleInstance(TaskManager);
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger); HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, GetHttpMessageHandler);
RegisterSingleInstance(HttpClient); RegisterSingleInstance(HttpClient);
NetworkManager = new NetworkManager(); NetworkManager = new NetworkManager();
@ -286,6 +287,8 @@ namespace MediaBrowser.Common.Implementations
}); });
} }
protected abstract HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression);
/// <summary> /// <summary>
/// Gets a list of types within an assembly /// Gets a list of types within an assembly
/// This will handle situations that would normally throw an exception - such as a type within the assembly that depends on some other non-existant reference /// This will handle situations that would normally throw an exception - such as a type within the assembly that depends on some other non-existant reference

View File

@ -9,8 +9,6 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -33,6 +31,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// </summary> /// </summary>
private readonly IApplicationPaths _appPaths; private readonly IApplicationPaths _appPaths;
public delegate HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression);
private readonly GetHttpMessageHandler _getHttpMessageHandler;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HttpClientManager" /> class. /// Initializes a new instance of the <see cref="HttpClientManager" /> class.
/// </summary> /// </summary>
@ -43,7 +45,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// or /// or
/// logger /// logger
/// </exception> /// </exception>
public HttpClientManager(IApplicationPaths appPaths, ILogger logger) public HttpClientManager(IApplicationPaths appPaths, ILogger logger, GetHttpMessageHandler getHttpMessageHandler)
{ {
if (appPaths == null) if (appPaths == null)
{ {
@ -55,6 +57,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
} }
_logger = logger; _logger = logger;
_getHttpMessageHandler = getHttpMessageHandler;
_appPaths = appPaths; _appPaths = appPaths;
} }
@ -85,15 +88,9 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
if (!_httpClients.TryGetValue(key, out client)) if (!_httpClients.TryGetValue(key, out client))
{ {
var handler = new WebRequestHandler
{
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
};
client = new HttpClientInfo client = new HttpClientInfo
{ {
HttpClient = new HttpClient(handler) HttpClient = new HttpClient(_getHttpMessageHandler(enableHttpCompression))
{ {
Timeout = TimeSpan.FromSeconds(20) Timeout = TimeSpan.FromSeconds(20)
} }

View File

@ -54,7 +54,6 @@
<Reference Include="System.Management" /> <Reference Include="System.Management" />
<Reference Include="System.Net" /> <Reference Include="System.Net" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -101,9 +101,9 @@
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net45\System.Reactive.Linq.dll</HintPath> <HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net45\System.Reactive.Linq.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Runtime.Serialization" /> <Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -50,6 +50,9 @@ using System.Data.SQLite;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Cache;
using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -660,5 +663,14 @@ namespace MediaBrowser.ServerApplication
{ {
get { return Constants.MbServerPkgName; } get { return Constants.MbServerPkgName; }
} }
protected override HttpMessageHandler GetHttpMessageHandler(bool enableHttpCompression)
{
return new WebRequestHandler
{
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate),
AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None
};
}
} }
} }

View File

@ -184,6 +184,8 @@
</Reference> </Reference>
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Net" /> <Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Remoting" /> <Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">