File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed
Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ public Uri BaseUrl
1717 set { _baseUrl = new ( ( ) => value ) ; }
1818 }
1919
20+ public TimeSpan Timeout { get ; set ; } = TimeSpan . FromMinutes ( 1 ) ;
21+
2022 Lazy < string > _apiKey = new ( ( ) =>
2123 Environment . GetEnvironmentVariable ( "ORB_API_KEY" )
2224 ?? throw new OrbInvalidDataException (
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ public interface IOrbClient
2727
2828 Uri BaseUrl { get ; init ; }
2929
30+ TimeSpan Timeout { get ; init ; }
31+
3032 string APIKey { get ; init ; }
3133
3234 string ? WebhookSecret { get ; init ; }
Original file line number Diff line number Diff line change 11using System ;
22using System . Net . Http ;
3+ using System . Threading ;
34using System . Threading . Tasks ;
45using Orb . Core ;
56using Orb . Exceptions ;
@@ -38,6 +39,12 @@ public Uri BaseUrl
3839 init { this . _options . BaseUrl = value ; }
3940 }
4041
42+ public TimeSpan Timeout
43+ {
44+ get { return this . _options . Timeout ; }
45+ init { this . _options . Timeout = value ; }
46+ }
47+
4148 public string APIKey
4249 {
4350 get { return this . _options . APIKey ; }
@@ -154,11 +161,16 @@ public async Task<HttpResponse> Execute<T>(HttpRequest<T> request)
154161 Content = request . Params . BodyContent ( ) ,
155162 } ;
156163 request . Params . AddHeadersToRequest ( requestMessage , this ) ;
164+ using CancellationTokenSource cts = new ( this . Timeout ) ;
157165 HttpResponseMessage responseMessage ;
158166 try
159167 {
160168 responseMessage = await this
161- . HttpClient . SendAsync ( requestMessage , HttpCompletionOption . ResponseHeadersRead )
169+ . HttpClient . SendAsync (
170+ requestMessage ,
171+ HttpCompletionOption . ResponseHeadersRead ,
172+ cts . Token
173+ )
162174 . ConfigureAwait ( false ) ;
163175 }
164176 catch ( HttpRequestException e1 )
You can’t perform that action at this time.
0 commit comments