diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index a00614c4f5..56dcc780d2 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -99,6 +99,19 @@ public GitHubClient(IConnection connection) Reaction = new ReactionsClient(apiConnection); } + /// + /// Set the GitHub Api request timeout. + /// Useful to set a specific timeout for lengthy operations, such as uploading release assets + /// + /// + /// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx + /// + /// The Timeout value + void SetRequestsTimeout(TimeSpan timeout) + { + Connection.SetRequestsTimeout(timeout); + } + /// /// Gets the latest API Info - this will be null if no API calls have been made /// diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 7ca86ff77a..abe23c7e18 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -752,5 +752,14 @@ static string GetVersionInformation() return _versionInformation; } + + /// + /// Set the timespan to wait before the requests to GitHub api times out. + /// + /// the timespan to wait before a request to GitHub api times out + public void SetRequestsTimeout(TimeSpan timeout) + { + _httpClient.SetRequestsTimeout(timeout); + } } } diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 24c56cca34..764693242f 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -264,6 +264,11 @@ public static async Task CloneHttpRequestMessageAsync(HttpRe return newRequest; } + + public void SetRequestsTimeout(TimeSpan timeout) + { + _http.Timeout = timeout; + } } internal class RedirectHandler : DelegatingHandler diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index ad649d7572..ab16e8d7e1 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -292,5 +292,11 @@ public interface IConnection : IApiInfoProvider /// the default with just these credentials. /// Credentials Credentials { get; set; } + + /// + /// Set the timespan to wait before the requests to GitHub api times out. + /// + /// the timespan to wait before a request to GitHub api times out + void SetRequestsTimeout(TimeSpan timeout); } } diff --git a/Octokit/Http/IHttpClient.cs b/Octokit/Http/IHttpClient.cs index f554d750dc..a4535ce4c2 100644 --- a/Octokit/Http/IHttpClient.cs +++ b/Octokit/Http/IHttpClient.cs @@ -19,5 +19,12 @@ public interface IHttpClient : IDisposable /// Used to cancel the request /// A of Task Send(IRequest request, CancellationToken cancellationToken); + + + /// + /// Set the timespan to wait before the requests to GitHub api times out. + /// + /// the timespan to wait before a request to GitHub api times out + void SetRequestsTimeout(TimeSpan timeout); } }