massaging and fighting with fxcop

This commit is contained in:
Brendan Forster
2015-05-22 16:46:24 +09:30
parent 14fe8bcbcd
commit 7f95f55d47
2 changed files with 30 additions and 13 deletions
+27 -11
View File
@@ -18,21 +18,25 @@ namespace Octokit.Internal
public class HttpClientAdapter : IHttpClient
{
readonly IWebProxy _webProxy;
HttpClient _http;
readonly HttpClient _http;
public HttpClientAdapter() { }
public HttpClientAdapter(IWebProxy webProxy, HttpMessageHandler handler = null)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public HttpClientAdapter(IWebProxy webProxy)
{
_webProxy = webProxy;
var handler = GetHandler();
_http = new HttpClient(new RedirectHandler { InnerHandler = handler });
}
if (handler == null)
{
handler = GetHandler();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public HttpClientAdapter(IWebProxy webProxy, HttpMessageHandler handler)
{
Ensure.ArgumentNotNull(handler, "handler");
_http = new HttpClient(new RedirectHandler() { InnerHandler = handler});
_webProxy = webProxy;
_http = new HttpClient(new RedirectHandler { InnerHandler = handler});
}
/// <summary>
@@ -71,8 +75,7 @@ namespace Octokit.Internal
return cancellationTokenForRequest;
}
private HttpClientHandler GetHandler()
HttpClientHandler GetHandler()
{
var httpOptions = new HttpClientHandler
{
@@ -174,6 +177,20 @@ namespace Octokit.Internal
}
return null;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_http != null) _http.Dispose();
}
}
}
public class RedirectHandler : DelegatingHandler
@@ -182,7 +199,6 @@ namespace Octokit.Internal
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken);
var allowAutoRedirect = (bool)request.Properties["AllowAutoRedirect"];
+3 -2
View File
@@ -1,4 +1,5 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Octokit.Internal
@@ -9,7 +10,7 @@ namespace Octokit.Internal
/// <remarks>
/// Most folks won't ever need to swap this out. But if you're trying to run this on Windows Phone, you might.
/// </remarks>
public interface IHttpClient
public interface IHttpClient : IDisposable
{
/// <summary>
/// Sends the specified request and returns a response.