Skip to content

Commit d9eee1a

Browse files
committed
Fixed Conflict
1 parent 67d1d7c commit d9eee1a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

CSharpHTTPClient/Client.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ public virtual Dictionary<string, string> DeserializeResponseHeaders(HttpRespons
6363

6464
public class Client : DynamicObject
6565
{
66+
private static HttpClient _httpClient = new HttpClient();
6667
public string Host;
6768
public Dictionary <string,string> RequestHeaders;
6869
public string Version;
6970
public string UrlPath;
7071
public string MediaType;
72+
public WebProxy WebProxy;
7173
public TimeSpan Timeout;
7274

7375
public enum Methods
@@ -77,6 +79,21 @@ public enum Methods
7779

7880
private int TimeoutDefault = 10;
7981

82+
/// <summary>
83+
/// REST API client.
84+
/// </summary>
85+
/// <param name="host">Base url (e.g. https://api.sendgrid.com)</param>
86+
/// <param name="requestHeaders">A dictionary of request headers</param>
87+
/// <param name="version">API version, override AddVersion to customize</param>
88+
/// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint)</param>
89+
/// <returns>Fluent interface to a REST API</returns>
90+
public Client(WebProxy webProxy, string host, Dictionary<string, string> requestHeaders = null, string version = null, string urlPath = null)
91+
: this(host, requestHeaders, version, urlPath)
92+
{
93+
WebProxy = webProxy;
94+
}
95+
96+
8097
/// <summary>
8198
/// REST API client.
8299
/// </summary>
@@ -165,6 +182,29 @@ private Client BuildClient(string name = null)
165182

166183
}
167184

185+
/// Factory method to return the right HttpClient settings.
186+
/// </summary>
187+
/// <returns>Instance of HttpClient</returns>
188+
private HttpClient BuildHttpClient()
189+
{
190+
// Add the WebProxy if set
191+
if (WebProxy != null)
192+
{
193+
var httpClientHandler = new HttpClientHandler()
194+
{
195+
Proxy = WebProxy,
196+
PreAuthenticate = true,
197+
UseDefaultCredentials = false,
198+
};
199+
200+
return new HttpClient(httpClientHandler);
201+
}
202+
203+
return _httpClient;
204+
}
205+
206+
/// <summary>
207+
168208
/// <summary>
169209
/// Add the authorization header, override to customize
170210
/// </summary>

0 commit comments

Comments
 (0)