Skip to content

Commit

Permalink
Add possibility to configure GitHubClient timeout (#963)
Browse files Browse the repository at this point in the history
A first attempt to fix the problem describe in #963 by adding a possibility
to extend the default timeout value (100s)
that is too short to be able to post assets in github release.
  • Loading branch information
pmiossec committed Oct 23, 2017
1 parent 0f0a0dc commit f09fd4e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Octokit.Reactive/IObservableGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ public interface IObservableGitHubClient : IApiInfoProvider
{
IConnection Connection { get; }

/// <summary>
/// Set the GitHub Api request timeout.
/// Useful to set a specific timeout for lengthy operations, such as uploading release assets
/// </summary>
/// <remarks>
/// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx
/// </remarks>
/// <param name="timeout">The Timeout value</param>
void SetRequestsTimeout(TimeSpan timeout);

IObservableAuthorizationsClient Authorization { get; }
IObservableActivitiesClient Activity { get; }
IObservableIssuesClient Issue { get; }
Expand Down
6 changes: 6 additions & 0 deletions Octokit.Reactive/ObservableGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
15 changes: 15 additions & 0 deletions Octokit.Tests/GitHubClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ public void IsRetrievedFromCredentialStore()
}
}

public class SettingRequestsTimeout
{
[Fact]
public void WhenSettingTimeoutThatSetTheRequestsTimeoutOnTheUnderlyingHttpClient()
{
var httpClient = Substitute.For<IHttpClient>();
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]
Expand Down
13 changes: 13 additions & 0 deletions Octokit/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ public GitHubClient(IConnection connection)
Reaction = new ReactionsClient(apiConnection);
}

/// <summary>
/// Set the GitHub Api request timeout.
/// Useful to set a specific timeout for lengthy operations, such as uploading release assets
/// </summary>
/// <remarks>
/// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx
/// </remarks>
/// <param name="timeout">The Timeout value</param>
public void SetRequestsTimeout(TimeSpan timeout)
{
Connection.SetRequestsTimeout(timeout);
}

/// <summary>
/// Gets the latest API Info - this will be null if no API calls have been made
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Octokit/Http/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,5 +752,14 @@ static string GetVersionInformation()

return _versionInformation;
}

/// <summary>
/// Set the timespan to wait before the requests to GitHub api times out.
/// </summary>
/// <param name="timeout">the timespan to wait before a request to GitHub api times out</param>
public void SetRequestsTimeout(TimeSpan timeout)
{
_httpClient.SetRequestsTimeout(timeout);
}
}
}
5 changes: 5 additions & 0 deletions Octokit/Http/HttpClientAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public static async Task<HttpRequestMessage> CloneHttpRequestMessageAsync(HttpRe

return newRequest;
}

public void SetRequestsTimeout(TimeSpan timeout)
{
_http.Timeout = timeout;
}
}

internal class RedirectHandler : DelegatingHandler
Expand Down
6 changes: 6 additions & 0 deletions Octokit/Http/IConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,11 @@ public interface IConnection : IApiInfoProvider
/// the default <see cref="InMemoryCredentialStore"/> with just these credentials.
/// </remarks>
Credentials Credentials { get; set; }

/// <summary>
/// Set the timespan to wait before the requests to GitHub api times out.
/// </summary>
/// <param name="timeout">the timespan to wait before a request to GitHub api times out</param>
void SetRequestsTimeout(TimeSpan timeout);
}
}
7 changes: 7 additions & 0 deletions Octokit/Http/IHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ public interface IHttpClient : IDisposable
/// <param name="cancellationToken">Used to cancel the request</param>
/// <returns>A <see cref="Task" /> of <see cref="IResponse"/></returns>
Task<IResponse> Send(IRequest request, CancellationToken cancellationToken);


/// <summary>
/// Set the timespan to wait before the requests to GitHub api times out.
/// </summary>
/// <param name="timeout">the timespan to wait before a request to GitHub api times out</param>
void SetRequestsTimeout(TimeSpan timeout);
}
}
10 changes: 10 additions & 0 deletions Octokit/IGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ namespace Octokit
/// </summary>
public interface IGitHubClient : IApiInfoProvider
{
/// <summary>
/// Set the GitHub Api request timeout.
/// Useful to set a specific timeout for lengthy operations, such as uploading release assets
/// </summary>
/// <remarks>
/// See more information here: https://technet.microsoft.com/library/system.net.http.httpclient.timeout(v=vs.110).aspx
/// </remarks>
/// <param name="timeout">The Timeout value</param>
void SetRequestsTimeout(TimeSpan timeout);

/// <summary>
/// Provides a client connection to make rest requests to HTTP endpoints.
/// </summary>
Expand Down

0 comments on commit f09fd4e

Please sign in to comment.