Skip to content

Commit 7968586

Browse files
Document Timeout behavior for RestClientOptions and RestRequest
Co-authored-by: alexeyzimarev <[email protected]>
1 parent 9b373a4 commit 7968586

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

docs/docs/advanced/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ RestSharp allows configuring `RestClient` using client options, as mentioned at
172172
| `RemoteCertificateValidationCallback` | Custom function to validate the server certificate. Normally, it's used when the server uses a certificate that isn't trusted by default. |
173173
| `BaseHost` | Value for the `Host` header sent with each request. |
174174
| `CookieContainer` | Custom cookie container that will be shared among all calls made by the client. Normally not required as RestSharp handles cookies without using a client-level cookie container. |
175-
| `MaxTimeout` | Client-level timeout in milliseconds. If the request timeout is also set, this value isn't used. |
175+
| `Timeout` | Client-level timeout as `TimeSpan`. Used when the request timeout is not specified using `RestRequest.Timeout`. If not set, the default timeout is 100 seconds. Set to `Timeout.InfiniteTimeSpan` (or `TimeSpan.FromMilliseconds(-1)`) for no timeout. Setting to `TimeSpan.Zero` will cancel the request immediately. Negative values other than -1 millisecond will throw an exception. |
176176
| `Encoding` | Default request encoding. Override it only if you don't use UTF-8. |
177177
| `ThrowOnDeserializationError` | Forces the client to throw if it fails to deserialize the response. Remember that not all deserialization issues forces the serializer to throw. Default is `false`, so the client will return a `RestResponse` with deserialization exception details. Only relevant for `Execute...` functions. |
178178
| `FailOnDeserializationError` | When set to `true`, if the client fails to deserialize the response, the response object will have status `Failed`, although the HTTP calls might have been successful. Default is `true`. |
@@ -213,7 +213,7 @@ Client options apply to all requests made by the client. Sometimes, you want to
213213
| `Authenticator` | Overrides the client-level authenticator. |
214214
| `Files` | Collection of file parameters, read-only. Use `AddFile` for adding files to the request. |
215215
| `Method` | Request HTTP method, default is `GET`. Only needed when using `Execute` or `ExecuteAsync` as other functions like `ExecutePostAsync` will override the request method. |
216-
| `TImeout` | Overrides the client-level timeout. |
216+
| `Timeout` | Overrides the client-level timeout. If not set, uses the client timeout or the default of 100 seconds. Set to `Timeout.InfiniteTimeSpan` (or `TimeSpan.FromMilliseconds(-1)`) for no timeout. Setting to `TimeSpan.Zero` will cancel the request immediately. Negative values other than -1 millisecond will throw an exception. |
217217
| `Resource` | Resource part of the remote endpoint URL. For example, when using the client-level base URL `https://localhost:5000/api` and `Resource` set to `weather`, the request will be sent to `https://localhost:5000/api/weather`. It can container resource placeholders to be used in combination with `AddUrlSegment` |
218218
| `RequestFormat` | Identifies the request as JSON, XML, binary, or none. Rarely used because the client will set the request format based on the body type if functions like `AddJsonBody` or `AddXmlBody` are used. |
219219
| `RootElement` | Used by the default deserializers to determine where to start deserializing from. Only supported for XML responses. Does not apply to requests. |

src/RestSharp/Options/RestClientOptions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,16 @@ public RestClientOptions(string baseUrl) : this(new Uri(Ensure.NotEmptyString(ba
183183
public CookieContainer? CookieContainer { get; set; }
184184

185185
/// <summary>
186-
/// Request duration. Used when the request timeout is not specified using <seealso cref="RestRequest.Timeout"/>,
187-
/// </summary>
186+
/// Request timeout duration. Used when the request timeout is not specified using <seealso cref="RestRequest.Timeout"/>.
187+
/// If not set, the default timeout is 100 seconds.
188+
/// </summary>
189+
/// <remarks>
190+
/// <list type="bullet">
191+
/// <item><description>Set to <see cref="System.Threading.Timeout.InfiniteTimeSpan"/> (or <c>TimeSpan.FromMilliseconds(-1)</c>) for no timeout</description></item>
192+
/// <item><description>Set to <see cref="TimeSpan.Zero"/> to cancel the request immediately</description></item>
193+
/// <item><description>Negative values (other than -1 millisecond) will throw <see cref="ArgumentOutOfRangeException"/></description></item>
194+
/// </list>
195+
/// </remarks>
188196
public TimeSpan? Timeout { get; set; }
189197

190198
/// <summary>

src/RestSharp/Request/RestRequest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,16 @@ public RestRequest(Uri resource, Method method = Method.Get)
131131
public Method Method { get; set; }
132132

133133
/// <summary>
134-
/// Custom request timeout
134+
/// Custom request timeout. Overrides <see cref="RestClientOptions.Timeout"/> if set.
135+
/// If not set, uses the client-level timeout or the default of 100 seconds.
135136
/// </summary>
137+
/// <remarks>
138+
/// <list type="bullet">
139+
/// <item><description>Set to <see cref="System.Threading.Timeout.InfiniteTimeSpan"/> (or <c>TimeSpan.FromMilliseconds(-1)</c>) for no timeout</description></item>
140+
/// <item><description>Set to <see cref="TimeSpan.Zero"/> to cancel the request immediately</description></item>
141+
/// <item><description>Negative values (other than -1 millisecond) will throw <see cref="ArgumentOutOfRangeException"/></description></item>
142+
/// </list>
143+
/// </remarks>
136144
public TimeSpan? Timeout { get; set; }
137145

138146
/// <summary>

0 commit comments

Comments
 (0)