Improved http timeout handling
This commit is contained in:
parent
1bba7e177b
commit
f87a66fcba
|
@ -131,6 +131,16 @@ namespace NzbDrone.Common.Test.Http
|
||||||
response.Content.Should().NotBeNullOrWhiteSpace();
|
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]
|
[Test]
|
||||||
public async Task should_execute_https_get()
|
public async Task should_execute_https_get()
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,6 +102,8 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||||
|
|
||||||
var httpClient = GetClient(request.Url);
|
var httpClient = GetClient(request.Url);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
using var responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, cts.Token);
|
using var responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, cts.Token);
|
||||||
{
|
{
|
||||||
byte[] data = null;
|
byte[] data = null;
|
||||||
|
@ -129,6 +131,11 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||||
return new HttpResponse(request, new HttpHeader(headers), data, responseMessage.StatusCode, responseMessage.Version);
|
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)
|
protected virtual System.Net.Http.HttpClient GetClient(HttpUri uri)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue