diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index e971972e..2b2cb50b 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -6,6 +6,16 @@ namespace Octokit.Reactive { 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 3745687f..87dc1705 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -54,6 +54,20 @@ namespace Octokit.Reactive 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 9f466e7d..2a02aaa8 100644 --- a/Octokit.Tests/GitHubClientTests.cs +++ b/Octokit.Tests/GitHubClientTests.cs @@ -196,5 +196,20 @@ namespace Octokit.Tests 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 a00614c4..a630e912 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -99,6 +99,19 @@ namespace Octokit 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 7ca86ff7..021d5be8 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -752,5 +752,14 @@ namespace Octokit 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 24c56cca..ca14a348 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -264,6 +264,15 @@ namespace Octokit.Internal 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 ad649d75..98c0380c 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -292,5 +292,11 @@ namespace Octokit /// 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 f554d750..584bef9f 100644 --- a/Octokit/Http/IHttpClient.cs +++ b/Octokit/Http/IHttpClient.cs @@ -19,5 +19,12 @@ namespace Octokit.Internal /// 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 0fd4b914..e411dc0c 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. ///