-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Document Timeout property behavior for RestClientOptions and RestRequest #2331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+68
−5
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9b373a4
Initial plan
Copilot 7968586
Document Timeout behavior for RestClientOptions and RestRequest
Copilot 3071c69
Improve timeout documentation with dedicated section
Copilot 23739fe
Add migration note about MaxTimeout to Timeout property
Copilot f84bd32
Merge branch 'dev' into copilot/add-documentation-for-timeouts
alexeyzimarev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,7 +172,7 @@ RestSharp allows configuring `RestClient` using client options, as mentioned at | |
| | `RemoteCertificateValidationCallback` | Custom function to validate the server certificate. Normally, it's used when the server uses a certificate that isn't trusted by default. | | ||
| | `BaseHost` | Value for the `Host` header sent with each request. | | ||
| | `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. | | ||
| | `MaxTimeout` | Client-level timeout in milliseconds. If the request timeout is also set, this value isn't used. | | ||
| | `Timeout` | Client-level timeout as `TimeSpan`. Default is 100 seconds. See [Configuring Timeouts](#configuring-timeouts) for details on timeout behavior. | | ||
| | `Encoding` | Default request encoding. Override it only if you don't use UTF-8. | | ||
| | `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. | | ||
| | `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 | |
| | `Authenticator` | Overrides the client-level authenticator. | | ||
| | `Files` | Collection of file parameters, read-only. Use `AddFile` for adding files to the request. | | ||
| | `Method` | Request HTTP method, default is `GET`. Only needed when using `Execute` or `ExecuteAsync` as other functions like `ExecutePostAsync` will override the request method. | | ||
| | `TImeout` | Overrides the client-level timeout. | | ||
| | `Timeout` | Request-level timeout override. See [Configuring Timeouts](#configuring-timeouts) for details on timeout behavior. | | ||
| | `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` | | ||
| | `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. | | ||
| | `RootElement` | Used by the default deserializers to determine where to start deserializing from. Only supported for XML responses. Does not apply to requests. | | ||
|
|
@@ -228,3 +228,50 @@ Client options apply to all requests made by the client. Sometimes, you want to | |
| | `Interceptors` | Allows adding interceptors to the request. Both client-level and request-level interceptors will be called. | | ||
|
|
||
| The table below contains all configuration properties of `RestRequest`. To learn more about adding request parameters, check the [usage page](../usage/request.md) page about creating requests with parameters. | ||
|
|
||
| ## Configuring Timeouts | ||
|
|
||
| RestSharp provides flexible timeout configuration at both the client and request levels. The timeout determines how long RestSharp will wait for a response before canceling the request. | ||
|
|
||
| :::note Migration from MaxTimeout | ||
| In older versions of RestSharp, the `MaxTimeout` property (measured in milliseconds) was used. This has been replaced by the `Timeout` property, which uses `TimeSpan` for more intuitive and type-safe timeout configuration. | ||
| ::: | ||
|
Comment on lines
+236
to
+238
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Maxtimeout still documented The PR updates configuration docs to say MaxTimeout was replaced by Timeout, but other non-versioned docs still show MaxTimeout usage and lists. Users following those examples will hit compilation errors and conflicting guidance. Agent Prompt
|
||
|
|
||
| ### Timeout Resolution | ||
|
|
||
| When making a request, RestSharp uses the following priority order to determine the timeout: | ||
| 1. `RestRequest.Timeout` (if set) | ||
| 2. `RestClientOptions.Timeout` (if set) | ||
| 3. Default timeout of 100 seconds | ||
|
|
||
| ### Timeout Values | ||
|
|
||
| The `Timeout` property accepts a `TimeSpan?` value and supports the following behaviors: | ||
|
|
||
| | Value | Behavior | | ||
| |-------|----------| | ||
| | `null` (not set) | Uses the next level timeout (client timeout, then default 100 seconds) | | ||
| | Positive `TimeSpan` | Request times out after the specified duration (e.g., `TimeSpan.FromSeconds(30)`) | | ||
| | `Timeout.InfiniteTimeSpan` or `TimeSpan.FromMilliseconds(-1)` | No timeout - request will wait indefinitely for a response | | ||
| | `TimeSpan.Zero` | Request is canceled immediately (effectively no time allowed for the request) | | ||
| | Other negative values | Throws `ArgumentOutOfRangeException` when the request is executed | | ||
|
|
||
| ### Examples | ||
|
|
||
| ```csharp | ||
| // Client-level timeout of 30 seconds | ||
| var options = new RestClientOptions("https://api.example.com") { | ||
| Timeout = TimeSpan.FromSeconds(30) | ||
| }; | ||
| var client = new RestClient(options); | ||
|
|
||
| // Request-level timeout override | ||
| var request = new RestRequest("resource") { | ||
| Timeout = TimeSpan.FromSeconds(60) // This request gets 60 seconds | ||
| }; | ||
|
|
||
| // Infinite timeout (no timeout) | ||
| var longRunningRequest = new RestRequest("long-operation") { | ||
| Timeout = Timeout.InfiniteTimeSpan | ||
| }; | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. maxtimeout 0/-1 undocumented
📎 Requirement gap✓ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools