added hook for providing a proxy to HttpClientAdapter

This commit is contained in:
Brendan Forster
2014-01-15 16:40:44 -08:00
parent 364db535cd
commit 4105bc9119
2 changed files with 30 additions and 0 deletions

View File

@@ -36,6 +36,21 @@ namespace Octokit
{ {
} }
/// <summary>
/// Creates a new connection instance used to make requests of the GitHub API.
/// </summary>
/// <param name="productInformation">
/// The name (and optionally version) of the product using this library. This is sent to the server as part of
/// the user agent for analytics purposes.
/// </param>
/// <param name="httpClient">
/// The client to use for executing requests
/// </param>
public Connection(ProductHeaderValue productInformation, IHttpClient httpClient)
: this(productInformation, _defaultGitHubApiUrl, _anonymousCredentials, httpClient, new SimpleJsonSerializer())
{
}
/// <summary> /// <summary>
/// Creates a new connection instance used to make requests of the GitHub API. /// Creates a new connection instance used to make requests of the GitHub API.
/// </summary> /// </summary>

View File

@@ -18,6 +18,15 @@ namespace Octokit.Internal
/// </remarks> /// </remarks>
public class HttpClientAdapter : IHttpClient public class HttpClientAdapter : IHttpClient
{ {
readonly IWebProxy webProxy;
public HttpClientAdapter() { }
public HttpClientAdapter(IWebProxy webProxy)
{
this.webProxy = webProxy;
}
public async Task<IResponse<T>> Send<T>(IRequest request) public async Task<IResponse<T>> Send<T>(IRequest request)
{ {
Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(request, "request");
@@ -30,6 +39,12 @@ namespace Octokit.Internal
{ {
httpOptions.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; httpOptions.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
} }
if (httpOptions.SupportsProxy && webProxy != null)
{
httpOptions.UseProxy = true;
httpOptions.Proxy = webProxy;
}
var http = new HttpClient(httpOptions) var http = new HttpClient(httpOptions)
{ {