From cf58dc0836d0844425ebb0d7cf3b2ec3d22cfc57 Mon Sep 17 00:00:00 2001 From: Maarten Balliauw Date: Mon, 25 Jan 2021 08:40:14 +0100 Subject: [PATCH] Configure BearerTokenConnection timeout #102 --- src/YouTrackSharp/BearerTokenConnection.cs | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/YouTrackSharp/BearerTokenConnection.cs b/src/YouTrackSharp/BearerTokenConnection.cs index 426a5dfc..aa8683db 100644 --- a/src/YouTrackSharp/BearerTokenConnection.cs +++ b/src/YouTrackSharp/BearerTokenConnection.cs @@ -2,6 +2,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; +using JetBrains.Annotations; using YouTrackSharp.Internal; namespace YouTrackSharp @@ -10,6 +11,7 @@ namespace YouTrackSharp /// A class that represents a connection against a YouTrack server instance and provides an authenticated /// that uses a bearer token. /// + [PublicAPI] public class BearerTokenConnection : Connection { @@ -19,6 +21,8 @@ public class BearerTokenConnection private readonly string _bearerToken; private readonly Action _configureHandler; + + private TimeSpan _timeout = TimeSpan.FromSeconds(100); /// /// Creates an instance of the class. @@ -35,6 +39,25 @@ public BearerTokenConnection(string serverUrl, string bearerToken, Action + /// Gets or sets the timespan to wait before the request times out. + /// + /// + /// The default value is 100,000 milliseconds (100 seconds). + /// + public TimeSpan Timeout + { + get => _httpClient?.Timeout ?? _timeout; + set + { + _timeout = value; + if (_httpClient != null) + { + _httpClient.Timeout = _timeout; + } + } + } /// public override async Task GetAuthenticatedHttpClient() @@ -48,7 +71,8 @@ public override async Task GetAuthenticatedHttpClient() _httpClient = new HttpClient(handler) { - BaseAddress = ServerUri + BaseAddress = ServerUri, + Timeout = _timeout }; _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Constants.HttpContentTypes.ApplicationJson));