Skip to content

Commit

Permalink
Add possibility to configure GitHubClient timeout (octokit#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmiossec committed Oct 17, 2017
1 parent 0f0a0dc commit 2443dbb
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Octokit/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ public GitHubClient(IConnection connection)
Reaction = new ReactionsClient(apiConnection);
}

/// <summary>
/// Set the timespan to wait before the requests to GitHub api times out.
///
/// Exceptions:
/// T:System.ArgumentOutOfRangeException:
/// The timeout specified is less than or equal to zero and is not System.Threading.Timeout.InfiniteTimeSpan.
///
/// T:System.InvalidOperationException:
/// An operation has already been started on the current instance.
///
/// T:System.ObjectDisposedException:
/// The current instance has been disposed.
/// </summary>
/// <param name="timeout">the timespan to wait before a request to GitHub api times out</param>
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
19 changes: 19 additions & 0 deletions Octokit/Http/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,5 +752,24 @@ static string GetVersionInformation()

return _versionInformation;
}

/// <summary>
/// Set the timespan to wait before the requests to GitHub api times out.
///
/// Exceptions:
/// T:System.ArgumentOutOfRangeException:
/// The timeout specified is less than or equal to zero and is not System.Threading.Timeout.InfiniteTimeSpan.
///
/// T:System.InvalidOperationException:
/// An operation has already been started on the current instance.
///
/// T:System.ObjectDisposedException:
/// The current instance has been disposed.
/// </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
16 changes: 16 additions & 0 deletions Octokit/Http/IConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,21 @@ 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.
///
/// Exceptions:
/// T:System.ArgumentOutOfRangeException:
/// The timeout specified is less than or equal to zero and is not System.Threading.Timeout.InfiniteTimeSpan.
///
/// T:System.InvalidOperationException:
/// An operation has already been started on the current instance.
///
/// T:System.ObjectDisposedException:
/// The current instance has been disposed.
/// </summary>
/// <param name="timeout">the timespan to wait before a request to GitHub api times out</param>
void SetRequestsTimeout(TimeSpan timeout);
}
}
17 changes: 17 additions & 0 deletions Octokit/Http/IHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,22 @@ 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.
///
/// Exceptions:
/// T:System.ArgumentOutOfRangeException:
/// The timeout specified is less than or equal to zero and is not System.Threading.Timeout.InfiniteTimeSpan.
///
/// T:System.InvalidOperationException:
/// An operation has already been started on the current instance.
///
/// T:System.ObjectDisposedException:
/// The current instance has been disposed.
/// </summary>
/// <param name="timeout">the timespan to wait before a request to GitHub api times out</param>
void SetRequestsTimeout(TimeSpan timeout);
}
}

0 comments on commit 2443dbb

Please sign in to comment.