@@ -68,6 +68,7 @@ public class Client : DynamicObject
6868 public string Version ;
6969 public string UrlPath ;
7070 public string MediaType ;
71+ public TimeSpan Timeout ;
7172 public enum Methods
7273 {
7374 DELETE , GET , PATCH , POST , PUT
@@ -80,8 +81,9 @@ public enum Methods
8081 /// <param name="requestHeaders">A dictionary of request headers</param>
8182 /// <param name="version">API version, override AddVersion to customize</param>
8283 /// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint)</param>
84+ /// <param name="timeOut">Set an Timeout parameter for the HTTP Client</param>
8385 /// <returns>Fluent interface to a REST API</returns>
84- public Client ( string host , Dictionary < string , string > requestHeaders = null , string version = null , string urlPath = null )
86+ public Client ( string host , Dictionary < string , string > requestHeaders = null , string version = null , string urlPath = null , TimeSpan ? timeOut = null )
8587 {
8688 Host = host ;
8789 if ( requestHeaders != null )
@@ -90,6 +92,7 @@ public Client(string host, Dictionary<string,string> requestHeaders = null, stri
9092 }
9193 Version = ( version != null ) ? version : null ;
9294 UrlPath = ( urlPath != null ) ? urlPath : null ;
95+ Timeout = ( timeOut != null ) ? ( TimeSpan ) timeOut : TimeSpan . FromSeconds ( 10 ) ;
9396 }
9497
9598 /// <summary>
@@ -155,7 +158,7 @@ private Client BuildClient(string name = null)
155158 }
156159
157160 UrlPath = null ; // Reset the current object's state before we return a new one
158- return new Client ( Host , RequestHeaders , Version , endpoint ) ;
161+ return new Client ( Host , RequestHeaders , Version , endpoint , Timeout ) ;
159162
160163 }
161164
@@ -261,6 +264,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
261264 /// <returns>Response object</returns>
262265 public async virtual Task < Response > MakeRequest ( HttpClient client , HttpRequestMessage request )
263266 {
267+
264268 HttpResponseMessage response = await client . SendAsync ( request ) . ConfigureAwait ( false ) ;
265269 return new Response ( response . StatusCode , response . Content , response . Headers ) ;
266270 }
@@ -280,8 +284,10 @@ private async Task<Response> RequestAsync(string method, String requestBody = nu
280284 {
281285 // Build the URL
282286 client . BaseAddress = new Uri ( Host ) ;
287+ client . Timeout = Timeout ;
283288 string endpoint = BuildUrl ( queryParams ) ;
284289
290+
285291 // Build the request headers
286292 client . DefaultRequestHeaders . Accept . Clear ( ) ;
287293 if ( RequestHeaders != null )
0 commit comments