diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index e971972efb..2b2cb50b3e 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -6,6 +6,16 @@ public interface IObservableGitHubClient : IApiInfoProvider { IConnection Connection { get; } + /// + /// 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 SetRequestTimeout(TimeSpan timeout); + IObservableAuthorizationsClient Authorization { get; } IObservableActivitiesClient Activity { get; } IObservableIssuesClient Issue { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 3745687f44..87dc1705f2 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -54,6 +54,20 @@ public IConnection Connection get { return _gitHubClient.Connection; } } + /// + /// 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 + public void SetRequestTimeout(TimeSpan timeout) + { + + _gitHubClient.SetRequestTimeout(timeout); + } + public IObservableAuthorizationsClient Authorization { get; private set; } public IObservableActivitiesClient Activity { get; private set; } public IObservableIssuesClient Issue { get; private set; } diff --git a/Octokit.Tests/GitHubClientTests.cs b/Octokit.Tests/GitHubClientTests.cs index 9f466e7dfa..2a02aaa855 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -196,5 +196,20 @@ public async Task ReturnsObjectIfNotNew() var temp = connection.Received(1).GetLastApiInfo(); } } + + public class TheSetRequestTimeoutMethod + { + [Fact] + public void SetsTheTimeoutOnTheUnderlyingHttpClient() + { + var httpClient = Substitute.For(); + var client = new GitHubClient(new Connection(new ProductHeaderValue("OctokitTests"), httpClient)); + + client.SetRequestTimeout(TimeSpan.FromSeconds(15)); + + + httpClient.Received(1).SetRequestTimeout(TimeSpan.FromSeconds(15)); + } + } } } diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index a00614c4f5..a630e91254 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 + public void SetRequestTimeout(TimeSpan timeout) + { + Connection.SetRequestTimeout(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..021d5be8f0 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -752,5 +752,14 @@ static string GetVersionInformation() return _versionInformation; } + + /// + /// Set the GitHub Api request timeout. + /// + /// The Timeout value + public void SetRequestTimeout(TimeSpan timeout) + { + _httpClient.SetRequestTimeout(timeout); + } } } diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 24c56cca34..ca14a34821 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -264,6 +264,15 @@ public static async Task CloneHttpRequestMessageAsync(HttpRe return newRequest; } + + /// + /// Set the GitHub Api request timeout. + /// + /// The Timeout value + public void SetRequestTimeout(TimeSpan timeout) + { + _http.Timeout = timeout; + } } internal class RedirectHandler : DelegatingHandler diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index ad649d7572..98c0380c0f 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 GitHub Api request timeout. + /// + /// The Timeout value + void SetRequestTimeout(TimeSpan timeout); } } diff --git a/Octokit/Http/IHttpClient.cs b/Octokit/Http/IHttpClient.cs index f554d750dc..584bef9f79 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 GitHub Api request timeout. + /// + /// The Timeout value + void SetRequestTimeout(TimeSpan timeout); } } diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 0fd4b914e1..e411dc0cdc 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -7,6 +7,16 @@ namespace Octokit /// public interface IGitHubClient : IApiInfoProvider { + /// + /// 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 SetRequestTimeout(TimeSpan timeout); + /// /// Provides a client connection to make rest requests to HTTP endpoints. ///