-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
add Timeout functionality for http package #19831
Comments
Probably the best way to support this would be to add a separate http_timeout_client package that exposes an HttpTimeoutClient that wraps an existing client. |
This comment was originally written by theburnin...@gmail.com Is there any reason why timeout couldn't be added as an optional parameter to the existing clients? I think the usage pattern would be more obvious this way than having to first create a client, then create another (HttpTimeoutClient) to wrap around it before you do a HTTP request. |
The http package is based on a composition model where each layer (that is, a class implementing http.Client) is very simple and has a well-defined purpose. This model makes it very easy to mix and match functionality, but one of the costs is that the API for a layer has to be very simple in order to keep them easy to implement. It would be bad if everyone implementing their own [http.Client] had to re-implement the timeout logic from scratch.
The API wouldn't be that difficult. The constructor would look something like this: HttpTimeoutClient([HttpClient inner]) The user only needs to construct one client if they only care about one aspect of the client. |
This comment was originally written by theburning...@gmail.com Hi, thanks for the explanation, that makes a lot of sense. |
Issue #10411 has been merged into this issue. |
This comment was originally written by @seaneagan Doesn't https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-async.Future#id_timeout Example: http.read('http://google.com') |
I don't think HttpTimeoutClient can accomplish what we want. Users would like to actually cancel the inflight request. dart:html has abort() on HttpRequest Added Area-Pkg label. |
Marked this as being blocked by #22265. |
This issue has been moved to dart-lang/http#21. |
What if HTTP request succeeds after 5 seconds? |
@michpolicht +1 I am afraid this will waste resource! if the http request last for, say, 20s, then even if it "timeouts", the resource is still be used! |
How about set timeout to max 5-10 seconds? so when the data is not there, you could show some alert dialog by onTimeout callbak to ask user to refresh the page? i think 10 seconds is too much for regular user to wait tbh |
This issue was originally filed by theburnin...@gmail.com
What steps will clearly show the issue / need for enhancement?
What version of the product are you using? On what operating system?
Dart 1.5.1, http 0.11.1+1
The text was updated successfully, but these errors were encountered: