mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 19:11:30 +00:00
massaging and fighting with fxcop
This commit is contained in:
@@ -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"];
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user