-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Added ability to set the timeout of an HTTP request #502
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc47523
Added ability to set the timeout of an HTTP request.
basicn86 fdf342b
Removed unncessary file.
basicn86 6c89e3f
Adjusted Timeout setter to throw an out of range exception.
basicn86 0c448c6
Allow for infinite timespan on the Timeout property.
basicn86 058b50e
Added a comment.
basicn86 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 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
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.
Why should an assignment like
HtmlWeb.Timeout = -4567
be equivalent toHtmlWeb.Timeout = 0
, and why and how would some HAP user possibly expect -4567 being the same as 0 for timeout values?In my opinion it would rather make more sense to throw an ArgumentOutOfRangeException for TimeOut values less than or equal to zero except Timeout.Infinite (Timeout.Infinite is the value -1 which indicates inifinite timeout), equivalent to the behavior of HttpWebRequest.Timeout (rejecting negative values except Timeout.Infinite) and HttpClient.Timeout (rejecting TimeSpan values that are zero or less than zero except TimeSpan.Infinite).
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.
Good idea, I adjusted the setter to throw a ArgumentOutOfRangeException if the value is less than or equal to zero. Thanks!
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.
Note that i edited my comment, as i originally did not account for Timeout.Infinite (which is the value -1)
So, basically, the setter should throw if
value <= 0 && value != Timeout.Infinite
.(My apologies for this oversight in my original comment.)
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.
To be honest, I do not expect any users to be waiting infinitely for a document to load. The default value for
HttpClient.Timeout
andHttpWebRequest.Timeout
is 100,000 ms, or 100 seconds. Adding an infinite timeout is a bit troublesome sinceHttpWebRequest
requires an integer whileHttpClient
requires aTimespan
object to be passed instead. I think throwing an exception if the value is zero or less is more of a practical approach.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.
No, it's actually not troublesome :-) because Timeout.InfiniteTimeSpan is per definition a TimeSpan value of -1 millisecond. Therefore
TimeSpan.FromMilliseconds(-1)
(i.e.,TimeSpan.FromMilliseconds(Timeout.Infinite)
) equalsTimeout.InfiniteTimeSpan
. No special treatment necessary here, just pass the integer timeout value to TimeSpan.FromMilliseconds and Bob's your uncle...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.
Oh really? I thought
TimeSpan.FromMilliseconds(-1)
would throw an exception that it's out of bounds. In this case, we can change that if statement to be thisif (value <= 0 && value != -1) { throw new ArgumentOutOfRangeException(); }
There you go, works as expected.