Skip to content

Commit

Permalink
Use InfiniteTimeSpan as the default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocontrini committed Oct 27, 2023
1 parent 05388e1 commit 9fa8d4c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions PlainHttp/HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HttpRequest : IHttpRequest

public HttpRequestMessage? Message { get; protected set; }

public TimeSpan? Timeout { get; set; }
public TimeSpan Timeout { get; set; } = System.Threading.Timeout.InfiniteTimeSpan;

public Dictionary<string, string> Headers { get; set; } = new();

Expand Down Expand Up @@ -72,9 +72,9 @@ public async Task<IHttpResponse> SendAsync(CancellationToken cancellationToken =
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

// Enable timeout, if set
if (this.Timeout != null)
if (this.Timeout != System.Threading.Timeout.InfiniteTimeSpan)
{
cts.CancelAfter(this.Timeout.Value);
cts.CancelAfter(this.Timeout);
}

Stopwatch stopwatch = Stopwatch.StartNew();
Expand Down
4 changes: 2 additions & 2 deletions PlainHttp/HttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private async Task<T> ReadWrapper<T>(Func<TimeSpan, Task<T>> readFunc)
if (this.Request.HttpCompletionOption == HttpCompletionOption.ResponseHeadersRead)
{
// Calculate how much time we have left until the timeout
timeLeft = this.Request.Timeout != null
? this.Request.Timeout.Value - this.ElapsedTime
timeLeft = this.Request.Timeout != Timeout.InfiniteTimeSpan
? this.Request.Timeout - this.ElapsedTime
: Timeout.InfiniteTimeSpan;

// Start measuring how long the read will last
Expand Down
2 changes: 1 addition & 1 deletion PlainHttp/IHttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IHttpRequest
HttpMethod Method { get; set; }
IPayload? Payload { get; set; }
Uri? Proxy { get; set; }
TimeSpan? Timeout { get; set; }
TimeSpan Timeout { get; set; }
Uri Uri { get; set; }
HttpCompletionOption HttpCompletionOption { get; set; }

Expand Down

0 comments on commit 9fa8d4c

Please sign in to comment.