-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.breaking-change-requestThis tracks requests for feedback on breaking changesThis tracks requests for feedback on breaking changeslibrary-io
Description
Summary
With current APIs in Dart:IO, there is no way to abort the HttpClientRequest. Once HttpClientRequest has been sent, the request cannot be canceled until HttpClientResponse comes back. See the example below:
HttpClient client = new HttpClient();
client.getUrl(Uri.parse("http://www.example.com/"))
.then((HttpClientRequest request) {
// Optionally set up headers...
request.write();
// Optionally write to the request object...
// Then call close.
...
return request.close();
})
.then((HttpClientResponse response) {
// Process the response.
...
});Abort() will allow users to stop waiting for HttpClientResponse, so users can abort the request if it takes too long.
Function signature
abort([Object? exception, StackTrace? stackTrace]);The intended behavior
- The future returned by
close()will complete withexceptionandstackTraceif abort() is called prior toHttpClientResponsebeing available. The default value forexceptionandstackTracewill beHttpExceptionandStackTrace.empty. - Data cannot be sent through
IOSink's API after abort(). - In case of
HttpClientResponsereturning beforeabort, abort() will not make any effect.
Expected use case
HttpClient client = new HttpClient();
client.getUrl(Uri.parse("http://www.example.com/"))
.then((HttpClientRequest request) {
// Optionally set up headers...
request.write();
// Optionally write to the request object...
// Then call close.
Timer(Duration(seconds: 1), () {
request.abort(Exception("Customized value"));
});
return request.close();
})
.then((HttpClientResponse response) {
// Process the response.
...
}, onError: (e) {
// e will be `Exception("Customized value")`
});Expected impact
All classes extends or implements HttpClientRequest in Dart:IO will need to update accordingly.
Proposed Implementation
https://dart-review.googlesource.com/c/sdk/+/147339
Relative discussions
hpoul, sureshg, ahmadf20, amondnet, zahidaz and 1 more
Metadata
Metadata
Assignees
Labels
area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.breaking-change-requestThis tracks requests for feedback on breaking changesThis tracks requests for feedback on breaking changeslibrary-io