From 4105bc9119e43e7fcd5cbacaf818c401c8f7086a Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 15 Jan 2014 16:40:44 -0800 Subject: [PATCH] added hook for providing a proxy to HttpClientAdapter --- Octokit/Http/Connection.cs | 15 +++++++++++++++ Octokit/Http/HttpClientAdapter.cs | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index a330736c..d8366577 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -36,6 +36,21 @@ namespace Octokit { } + /// + /// Creates a new connection instance used to make requests of the GitHub API. + /// + /// + /// 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. + /// + /// + /// The client to use for executing requests + /// + public Connection(ProductHeaderValue productInformation, IHttpClient httpClient) + : this(productInformation, _defaultGitHubApiUrl, _anonymousCredentials, httpClient, new SimpleJsonSerializer()) + { + } + /// /// Creates a new connection instance used to make requests of the GitHub API. /// diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 5540c676..1656b023 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -18,6 +18,15 @@ namespace Octokit.Internal /// public class HttpClientAdapter : IHttpClient { + readonly IWebProxy webProxy; + + public HttpClientAdapter() { } + + public HttpClientAdapter(IWebProxy webProxy) + { + this.webProxy = webProxy; + } + public async Task> Send(IRequest request) { Ensure.ArgumentNotNull(request, "request"); @@ -30,6 +39,12 @@ namespace Octokit.Internal { httpOptions.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } + if (httpOptions.SupportsProxy && webProxy != null) + { + httpOptions.UseProxy = true; + httpOptions.Proxy = webProxy; + } + var http = new HttpClient(httpOptions) {