diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs
index e971972efb..234b8abaee 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 SetRequestsTimeout(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..7dd3a2febd 100644
--- a/Octokit.Reactive/ObservableGitHubClient.cs
+++ b/Octokit.Reactive/ObservableGitHubClient.cs
@@ -54,6 +54,12 @@ public IConnection Connection
get { return _gitHubClient.Connection; }
}
+ public void SetRequestsTimeout(TimeSpan timeout)
+ {
+
+ _gitHubClient.SetRequestsTimeout(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..b258c7d4fb 100644
--- a/Octokit.Tests/GitHubClientTests.cs
+++ b/Octokit.Tests/GitHubClientTests.cs
@@ -132,6 +132,21 @@ public void IsRetrievedFromCredentialStore()
}
}
+ public class SettingRequestsTimeout
+ {
+ [Fact]
+ public void WhenSettingTimeoutThatSetTheRequestsTimeoutOnTheUnderlyingHttpClient()
+ {
+ var httpClient = Substitute.For();
+ var client = new GitHubClient(new Connection(new ProductHeaderValue("OctokitTests"), httpClient));
+
+ client.SetRequestsTimeout(TimeSpan.FromSeconds(15));
+
+
+ httpClient.Received(1).SetRequestsTimeout(TimeSpan.FromSeconds(15));
+ }
+ }
+
public class TheLastApiInfoProperty
{
[Fact]
diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs
index a00614c4f5..9df01688cb 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 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);
}
}
diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs
index 0fd4b914e1..ae51df3984 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 SetRequestsTimeout(TimeSpan timeout);
+
///
/// Provides a client connection to make rest requests to HTTP endpoints.
///