Skip to content

Commit 895877a

Browse files
committed
If you have a timeout on the client AND a timeout on the request, the resulting actual timeout is going to be the shorter of the two. By default HttpClient has a timeout of 100 seconds built in, so that means if someone is expecting to be able to send a request and have it wait longer than 100 seconds, it won't work if the client is also changed.
So I propose we change the property in RestClientOptions which is then applied to HttpClient to be called MaxTimeout so it is a lot more clear what the connection is? You cannot have a longer timeout for any request unless you change this value. It might also make sense to set this to a default value of something (maybe 100 seconds to make it clear) rather than leaving it null, so the user of the library will be more aware of how the client timeout and request timeout interact with each other? The other option would be to always set the timeout in the client to infinite, and then always use a request timeout that is the Max() of either the client timeout or the request one if the request one was provided?
1 parent 17a3532 commit 895877a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/RestSharp/RestClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public RestClient(HttpClient httpClient, RestClientOptions options, bool dispose
124124
public RestClient(HttpMessageHandler handler, bool disposeHandler = true) : this(new HttpClient(handler, disposeHandler), true) { }
125125

126126
void ConfigureHttpClient(HttpClient httpClient) {
127-
if (Options.Timeout > 0) httpClient.Timeout = TimeSpan.FromMilliseconds(Options.Timeout);
127+
if (Options.MaxTimeout > 0) httpClient.Timeout = TimeSpan.FromMilliseconds(Options.MaxTimeout);
128128
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(Options.UserAgent);
129129
}
130130

src/RestSharp/RestClientOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public RestClientOptions(string baseUrl) : this(new Uri(Ensure.NotEmptyString(ba
7575
public bool FollowRedirects { get; set; } = true;
7676
public CookieContainer? CookieContainer { get; set; }
7777
public string UserAgent { get; set; } = DefaultUserAgent;
78-
public int Timeout { get; set; }
78+
public int MaxTimeout { get; set; }
7979
public Encoding Encoding { get; set; } = Encoding.UTF8;
8080

8181
/// <summary>

0 commit comments

Comments
 (0)