extracting all the cross-platform setup of HttpMessageHandler into

a less awful class
This commit is contained in:
Brendan Forster
2015-05-31 19:23:39 +09:30
parent 5d0c8d6679
commit e5e4b4c8b0
12 changed files with 56 additions and 57 deletions
+36
View File
@@ -0,0 +1,36 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
namespace Octokit.Internal
{
public static class HttpMessageHandlerFactory
{
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public static HttpClientHandler GetHandler()
{
return GetHandler(null);
}
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public static HttpClientHandler GetHandler(IWebProxy proxy)
{
var handler = new HttpClientHandler
{
AllowAutoRedirect = false
};
#if !PORTABLE
if (handler.SupportsAutomaticDecompression)
{
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
}
if (handler.SupportsProxy && proxy != null)
{
handler.UseProxy = true;
handler.Proxy = proxy;
}
#endif
return handler;
}
}
}