1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 18:02:44 +01:00

Improved http timeout handling

(cherry picked from commit f87a66fcba6ca9ca972fa1c747a940b216e0e5e3)
This commit is contained in:
Qstick 2024-01-14 15:25:25 -06:00 committed by Bogdan
parent ea470b4ee9
commit 1932aec131
2 changed files with 35 additions and 18 deletions

View File

@ -129,6 +129,16 @@ public async Task should_execute_simple_get()
response.Content.Should().NotBeNullOrWhiteSpace();
}
[Test]
public void should_throw_timeout_request()
{
var request = new HttpRequest($"https://{_httpBinHost}/delay/10");
request.RequestTimeout = new TimeSpan(0, 0, 5);
Assert.ThrowsAsync<WebException>(async () => await Subject.ExecuteAsync(request));
}
[Test]
public async Task should_execute_https_get()
{

View File

@ -102,6 +102,8 @@ public async Task<HttpResponse> GetResponseAsync(HttpRequest request, CookieCont
var httpClient = GetClient(request.Url);
try
{
using var responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, cts.Token);
{
byte[] data = null;
@ -129,6 +131,11 @@ public async Task<HttpResponse> GetResponseAsync(HttpRequest request, CookieCont
return new HttpResponse(request, new HttpHeader(headers), data, responseMessage.StatusCode, responseMessage.Version);
}
}
catch (OperationCanceledException ex) when (cts.IsCancellationRequested)
{
throw new WebException("Http request timed out", ex.InnerException, WebExceptionStatus.Timeout, null);
}
}
protected virtual System.Net.Http.HttpClient GetClient(HttpUri uri)
{