Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw TimeoutException upon HTTP timeout for GET operations #4128

Merged
merged 1 commit into from Mar 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions Duplicati/Library/Backend/OAuthHelper/OAuthHttpClient.cs
Expand Up @@ -64,6 +64,26 @@ private OAuthHttpClient(OAuthHttpMessageHandler authenticator)
this.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Duplicati", USER_AGENT_VERSION));
}

/// <summary>
/// Hide the base GetAsync method to throw a TimeoutException when an HTTP timeout occurs.
/// </summary>
public new async Task<System.Net.Http.HttpResponseMessage> GetAsync(string requestUri)
{
// The HttpClient.GetAsync method throws an OperationCanceledException when the timeout is exceeded.
// In order to provide a more informative exception, we will detect this case and throw a TimeoutException
// instead.
try
{
return await base.GetAsync(requestUri).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Since there is no CancellationToken, we will assume that the OperationCanceledException
// is due to an HTTP timeout.
throw new TimeoutException($"HTTP timeout {this.Timeout} exceeded.");
}
}

/// <summary>
/// Sends an async request with optional authentication.
/// </summary>
Expand Down