Revert PR 9 changes #11
Merged
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.
This PR is to revert the changes made in #9
If a timeout is required on the HttpClient it should be set on an HttpClient instance passed in via the
new SocketLabsClient(x, y, httpClient)
ctor call.Why?
A HttpClient timeout property cannot be modified after using it.
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.timeout?view=net-5.0
As the timeout is set during the SendAsync call, it will throw an error next time this code runs unless a new HttpClient instance is created for each send call. This has broken HttpClient reuse.
Please note the above - from the MSDN docs. If per-request timeouts are required, then CTS should be used on the task, causing the task to cancel.
If SendAsync is called for a second time on the same SocketLabsClient the following will be thrown:
I recommend reverting as a user can simply create their own HttpClient with their use case specific RequestTimeout, and then pass that configured client in via the constructor which allows this.
However, if per-request timeouts were required, and the SocketLabsClient wanted to support that, you could consider using CTS on the Task to cancel in-flight requests, however, this change is out of scope of this fix. I would also argue that the caller should configure this as required.