@@ -68,11 +68,27 @@ public class Client : DynamicObject
68
68
public string Version ;
69
69
public string UrlPath ;
70
70
public string MediaType ;
71
+ public WebProxy WebProxy ;
71
72
public enum Methods
72
73
{
73
74
DELETE , GET , PATCH , POST , PUT
74
75
}
75
76
77
+
78
+ /// <summary>
79
+ /// REST API client.
80
+ /// </summary>
81
+ /// <param name="host">Base url (e.g. https://api.sendgrid.com)</param>
82
+ /// <param name="requestHeaders">A dictionary of request headers</param>
83
+ /// <param name="version">API version, override AddVersion to customize</param>
84
+ /// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint)</param>
85
+ /// <returns>Fluent interface to a REST API</returns>
86
+ public Client ( WebProxy webProxy , string host , Dictionary < string , string > requestHeaders = null , string version = null , string urlPath = null )
87
+ : this ( host , requestHeaders , version , urlPath )
88
+ {
89
+ WebProxy = webProxy ;
90
+ }
91
+
76
92
/// <summary>
77
93
/// REST API client.
78
94
/// </summary>
@@ -159,6 +175,28 @@ private Client BuildClient(string name = null)
159
175
160
176
}
161
177
178
+ /// <summary>
179
+ /// Factory method to return the right HttpClient settings.
180
+ /// </summary>
181
+ /// <returns>Instance of HttpClient</returns>
182
+ private HttpClient BuildHttpClient ( )
183
+ {
184
+ // Add the WebProxy if set
185
+ if ( WebProxy != null )
186
+ {
187
+ var httpClientHandler = new HttpClientHandler ( )
188
+ {
189
+ Proxy = WebProxy ,
190
+ PreAuthenticate = true ,
191
+ UseDefaultCredentials = false ,
192
+ } ;
193
+
194
+ return new HttpClient ( httpClientHandler ) ;
195
+ }
196
+
197
+ return new HttpClient ( ) ;
198
+ }
199
+
162
200
/// <summary>
163
201
/// Add the authorization header, override to customize
164
202
/// </summary>
@@ -274,7 +312,7 @@ public async virtual Task<Response> MakeRequest(HttpClient client, HttpRequestMe
274
312
/// <returns>Response object</returns>
275
313
private async Task < Response > RequestAsync ( string method , string requestBody = null , string queryParams = null )
276
314
{
277
- using ( var client = new HttpClient ( ) )
315
+ using ( var client = BuildHttpClient ( ) )
278
316
{
279
317
try
280
318
{
0 commit comments