You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to come up with a design for supporting abort through the interfaces in this package and validate that we can build it on both dart:html and dart:io implementations.
The easiest option might be to add a method on StreamedResponse. There is some precedent for that with IOStreamedResponse.detachSocket.
Reacted by Jon Scalet, liranzairi, Vikey Chen, mnordine, Chandra Sekhar Kode, Dev Aggarwal, mono — Masayuki Ono, rockingdice, Herbert Poul, Max Anurin and 97 more
The easiest option might be to add a method on StreamedResponse.
The proposed dart:io's abort() is a method in Class HttpClientRequest. The
method on StreamedResponse should not be able to access
abort().(Technically you can, but it won't make a difference as the
response has already come back)
I think the only use case for abort() is timing out the request if it takes
too long. We can adapt `send` to accept an optional parameter `duration`
and possibly a callback to be fired when timing out.
Here are a couple other options - I'm not advocating for these, just trying to brainstorm. Both of these are breaking changes for anyone with implements http.Client.
Allow passing a Future back to the client to cancel it. We'd have some state that lets us abort if you give us back the exact same instance.
var response = client.get(url);
// something happens
client.abort(response);
Add a named argument to all the methods:
var abortCompleter =Completer<void>();
var response = client.get(url, abortOn: abortCompleter.future);
// something happens
abortCompleter.complete();
The latter could pair well with a timeout argument. Passing timeout: Duration(seconds: 5) would have the same effect as passing abortOn: Future.delayed(Duration(seconds: 5))
Hey, in my app I want to give the user an option to abort while uploading a file. I saw that dart:io is going to support it soon. However I use http package in my app so I looked here and saw this thread. Do you think you'll support it too, soon? Thanks
I think having an abort method on the response itself is really the ideal design here, for a few reasons:
It doesn't require the Client to keep track of outgoing requests. This is cleaner, more memory efficient, and less likely to result in memory leaks.
It is more intuitive as a user of the API - all the useful functionality is encapsulated on the response itself - you can pass that one object around to other parts of the code and they can decide to cancel it, etc. They don't also need a client, and you can decouple the knowledge about when to cancel from the service making the actual requests.
It allows you to synchronously cancel requests, instead of waiting an arbitrary amount of time for the event queue to catch up. This helps to mitigate race conditions between the cancellation and completion of the request, and it helps to waste less data by cancelling the request sooner.
This does get a bit trickier to implement - you are left with a few not so great options:
Implement Future with some custom type, which beyond being considered an anti-pattern also raises some difficult questions around how you handle the cancel case. I think for this you could just complete with a special type of error, and not try to do what CancelableOperation does (with a special onCancel callback that complicates error handling).
Make a user-facing breaking change in the api to return some new type (possibly CancelableOperation).
The trickiest part of this is rolling it out, I think no matter what design we use it's going to be a breaking change for anyone with a class which implements Client.
It doesn't require the Client to keep track of outgoing requests. This is cleaner, more memory efficient, and less likely to result in memory leaks.
I don't think that will be difficult in any case. We don't need an extra collection - we can handle this all at the point where we have the HttpClientRequest or the HttpRequest.
It is more intuitive as a user of the API - all the useful functionality is encapsulated on the response itself - you can pass that one object around to other parts of the code and they can decide to cancel it, etc. They don't also need a client, and you can decouple the knowledge about when to cancel from the service making the actual requests.
Attaching it to a StreamedResponse has the downside of pushing more users onto that API over http.get. I think cancellation (usually timeout) is a common enough use case that we want to support it on those APIs as well. Changing the return type from Future to CancelablleOperation is more breaking, and I'm not entirely convinced one way or the other whether it's a better API if we were starting from scratch.
It allows you to synchronously cancel requests, instead of waiting an arbitrary amount of time for the event queue to catch up. This helps to mitigate race conditions between the cancellation and completion of the request, and it helps to waste less data by cancelling the request sooner.
I would expect that the typical case cancelations only happen after some async trigger either way. I think at most we could shave a microtask or 2, but I don't think that gives much power to typical usages. Which likely can't make many guarantees about behavior even if we give them a synchronous cancel.
One thing that's tricky here, I didn't realize the dart:io implementation causes the done future to complete as an error as opposed to never completing. I'm pretty sure the implementation in the browsers wouldn't do that.
I think it would be easier to build the error behavior in the browser than to build the never-complete behavior for dart:io but probably either is possible.
I don't have a strong opinion between completing as error on abort, or never completing on abort. One nice thing about the error approach is that if you do want to forward an error object and stack trace through it's possible to do so.
cc @lrhn for opinions on completing as error vs never completing for aborted requests.
I really don't think abortOn with a Future type is the right api here... it has a lot of downsides. Specifically since you can't cancel the future at all I think it will be prone to memory leaks, hung processes on exit, and other similar issues.
How about just supporting the timeout argument which we can ensure is implemented better (using a timer which we can cancel) as opposed to a delayed future?
This is a must have feature. A lot of community backed packages are using this package at their core. And because there is not yet a abort functionality for downloads, there are huge amount of wasted data for Flutter users. This is really bad user experience when users check their data usage on their phones.
I am not sure why people are so concerned about breaking changes. Flutter is still new. Breaking changes are to be expected and for a core functionality like this, I am sure devs wont complain.
Imho what devs would really complain about could be a platform with APIs so hard to understand because they were patched for every new feature instead of getting redesigned. If we want Flutter to remain and feel fresh and different from the old and slow SDks then we have to live with breaking changes for a while.
Personally, the lack of aborting is a big deal for us because we have a video heavy app and we are using flutter_cache_manager to pre-download some of the videos in the list. If the user scrolls even further, we would like to abort the started downloads and start new ones. But for now we are stuck with 10's of started downloads which will be just byte waste.
Reacted by liranzairi, Gustav Trede, ab-rdarts, Ibrahim Berat Kaya, Tim Whiting, Albert Wolszon, harkairt, Umut ADALI, Jeandeson O. Merelis, Rafay Ali and 31 more
If the connection has not yet completed, the request is aborted and the done future (also returned by close) is completed with the provided exception and stackTrace. If exception is omitted, it defaults to an HttpException, and if stackTrace is omitted, it defaults to StackTrace.empty.
If the done future has already completed, aborting has no effect.
done (which is returned by close) is:
An HttpClientResponse future that will complete once the response is available.
If an error occurs before the response is available, this future will complete with an error.
So I would expect the abort to still do something until the response is available. In other words, I would expect it to be effective until we complete this line:
var response =await stream.pipe(ioRequest) asHttpClientResponse;
Therefore, I assume this means any response that the user manages to read for the IOClient will always be fully complete.
This is not the case for BrowserClient.
Does that make sense?
I can screen record to show you why I think that explains the behaviour I see.
If the connection has not yet completed, the request is aborted and the done future (also returned by close) is completed with the provided exception and stackTrace. If exception is omitted, it defaults to an HttpException, and if stackTrace is omitted, it defaults to StackTrace.empty.
If the done future has already completed, aborting has no effect.
done (which is returned by close) is:
An HttpClientResponse future that will complete once the response is available.
If an error occurs before the response is available, this future will complete with an error.
So I would expect the abort to still do something until the response is available. In other words, I would expect it to be effective until we complete this line:
var response = await stream.pipe(ioRequest) as HttpClientResponse;
Therefore, I assume this means any response that the user manages to read for the IOClient will always be fully complete.
This is not the case for BrowserClient.
Does that make sense?
I can screen record to show you why I think that explains the behaviour I see.
You could just start writing integration tests to verify the behavior. I'd be happy to send you some code to get started.
Ok, so some issues that seem to backup the difference in behaviour.
With the IOClient and "after response, client still useable" request:
test('after response, client still useable', () async {
final abortTrigger =Completer<void>();
final request =AbortableRequest(
'GET',
serverUrl,
abortTrigger: abortTrigger.future,
);
final abortResponse =await client.send(request);
abortTrigger.complete();
bool triggeredAbortedRequest =false;
try {
await abortResponse.stream.drain<void>();
} onAbortedRequest {
triggeredAbortedRequest =true;
}
final response =await client.get(serverUrl);
expect(response.statusCode, 200);
expect(response.body, endsWith('9999\n'));
expect(triggeredAbortedRequest, true);
});
triggeredAbortedRequest is false, and the test fails. IOClient does not throw and cannot throw AbortedRequest when reading the stream. It only happens on send. Since we cancel after send, it does not cause any error to throw.
The test is successful on BrowserClient.
This test seems potentially broken on both platforms:
test('while streaming response', () async {
final abortTrigger =Completer<void>();
final request =AbortableRequest(
'GET',
serverUrl,
abortTrigger: abortTrigger.future,
);
final response =await client.send(request);
var i =0;
expect(
response.stream.listen((data) {
++i;
if (i ==1000) abortTrigger.complete();
}).asFuture<void>(),
throwsA(isA<AbortedRequest>()),
);
expect(i, 1000);
}, skip: canStreamResponseBody ?false:'does not stream response bodies');
Why would the last expect statement wait for the loop to reach 1000? Should I have changed something here?
I would also expect it to fail on IOClient in the same way as above.
This test fails on IOClient and succeeds on BrowserClient:
test('after response', () async {
final abortTrigger =Completer<void>();
final request =AbortableRequest(
'GET',
serverUrl,
abortTrigger: abortTrigger.future,
);
final response =await client.send(request);
abortTrigger.complete();
expect(
response.stream.single,
throwsA(isA<AbortedRequest>()),
);
});
Expected: throws <Instance of 'AbortedRequest'>
Actual: <Instance of 'Future<List<int>>'>
Which: threw StateError:<Bad state: Too many elements>
stack
which is not an instance of 'AbortedRequest'
I can't quite figure out what that response is saying. Too many elements? But anyway, same as before, IOClient only throws on send.
I don't think it's possible to change the behaviour of IOClient to match BrowserClient since its under the control of dart:io. It might be possible to change the behaviour the other way to match, not sure the best way to do that. Is it even necessary?
...
This test seems potentially broken on both platforms:
test('while streaming response', () async {
final abortTrigger = Completer<void>();
final request = AbortableRequest(
'GET',
serverUrl,
abortTrigger: abortTrigger.future,
);
final response = await client.send(request);
var i = 0;
expect(
response.stream.listen((data) {
++i;
if (i == 1000) abortTrigger.complete();
}).asFuture<void>(),
throwsA(isA<AbortedRequest>()),
);
expect(i, 1000);
}, skip: canStreamResponseBody ? false : 'does not stream response bodies');
Why would the last expect statement wait for the loop to reach 1000? Should I have changed something here? I would also expect it to fail on IOClient in the same way as above.
The test is trying to confirm that you don't get any more data after you aport the request.
...
I don't think it's possible to change the behaviour of IOClient to match BrowserClient since its under the control of dart:io. It might be possible to change the behaviour the other way to match, not sure the best way to do that. Is it even necessary?
You can by proxying the Stream that HttpClient uses. Pseudocode:
// var response = await stream.pipe(ioRequest) as HttpClientResponse;final controller =StreamController<Uint8List>(onCancel: () {
subscription.cancel();
});
final subscription = ioRequest.listen((data) {
subscription.sink.add(data);
}, onDone: () async {await subscription.sink.close(); });
abortThing.then(() async {
// If the controller is already closed then the stream has already been consumed// by the caller or there was already another error.if (!controller.isClosed)
subscription.sink.addError(AbortedRequest(...));
await subscription.sink.close();
});
// Pass `controller.stream` to _StreamedResponseWithUrl
@brianquinlan I'm not quite sure what that's trying to do.
From my understanding:
stream.pipe(ioRequest)
This pumps the stream (which is the request body) into the opened connection, then closes the request/connection.
On closing the ioRequest, which happens within pipe, it returns the HTTP response
So I'm not sure what you meant by ioRequest.listen - it can't be listened to.
If abort is called after the pipe line, it is ineffective. Only after the pipe can we begin to read bytes. So I'm not sure it even makes sense to attempt to make the behaviour like BrowserClient.
@brianquinlan I'm not quite sure what that's trying to do.
From my understanding:
stream.pipe(ioRequest)
This pumps the stream (which is the request body) into the opened connection, then closes the request/connection.
On closing the ioRequest, which happens within pipe, it returns the HTTP response
So I'm not sure what you meant by ioRequest.listen - it can't be listened to.
Sorry, I meant you can listen to response.
If abort is called after the pipe line, it is ineffective. Only after the pipe can we begin to read bytes. So I'm not sure it even makes sense to attempt to make the behaviour like BrowserClient.
The entire premise of package:http is to provide a consistent interface across HTTP client implementations. That isn't always possible but, when it is possible (and I think that it is in this case), we try our best to make the Client's consistent.
I'm not sure it makes sense though, it would be a lie (the whole response is always available at that point).
dart:ioHttpClient streams the response (otherwise it would be impossible to do downloads that don't fit into memory).
Let me know if you can stuck on this and I can propose some code - if you do that could you upload what you have on your PR with my conformance tests included?
I've made IOClient mostly work in the way we want.
The limitation is that in the "while streaming response" test, the number of events received is larger than 1000 - it's always 1749. I would assume this is because of the way the events are emitted in batches. Even trying to use takeUntil instead of a custom implementation has the same issue, so I would assume it's unavoidable.
May also need to tweak it a little more to respect onListen on the controller etc. (and only start the subscription on the response then) so it doesn't waste memory, but I'm not sure if that's necessary.
I'm struggling to make BrowserClient meet the "while streaming response" test. In the event of abortion, it just completes the stream without an error. Additionally, it somehow only counts up to 13! I guess the solution is the same as for IOClient, but it's a little but more difficult to work with.
I might be able to take a look tomorrow, but if you wanted to have a look in the meantime, everything is up to date with your tests and my changes.
#1773 is definitely moving us in the right direction but I'm worried that landing it will be hard because of the flaky failures in IOClient and the work needed to make RetryClient work (let me know if you disagree @JaffaKetchup !)
What Client implementations do people care about? Because an alternative approach would be to incrementally support aborting requests i.e. we could start with BrowserClient, CupertinoHttp and CronetHttp. IOClient and RetryClient could display a warning saying that they don't support aborting requests if the abortTrigger future is completed e.g.
unawaited(abortTrigger.whenComplete(() =>print('IOClient does not support request cancellation. See https://github.com/dart-lang/http/issues/424));
We could add support for IOClient whenever someone has the time to do so.
Yeah, I can definitely see it might be tricky to get things working if I can't reproduce the issues :D
I've made a small change on #1773, could you run the tests again? It's ugly and I don't know if I expect it to work, but if it does, that confirms something(???) :D.
Unfortunately, the IO and browser clients are the ones I most care about - that's what we use by default in flutter_map (through the Client constructor). We do use RetryClient - I could work around that in the meantime - but again, ideally, it would be implemented. And looking at the pub.dev stats, the vast majority of users seem to be using the default clients (idk about retry) - so not implementing it fully but landing the feature wouldn't seem quite right IMO.
Could there be the option of disabling abortion for streamed requests for the time being - or simply refusing to abort requests while the data is being streamed in?
If it turns out we need to make a change to the Dart SDK, that complicates things ofc. I would hope that's not necessary though.
But as I'm very short on time for the next couple few weeks, and you are as well, I think leaving it for a few weeks is fine. Afterall, even if we managed to land it before your holiday somehow, I couldn't make good use of it for a few weeks. After that I'll have more time to figure things out (hopefully). Ofc if someone else wants it in the meantime... ;D
On a sort-of related note, I noticed https://pub.dev/packages/fetch_client. Doesn't the http implementation now use fetch as well? And after we've implemented this, wouldn't they both have the same feature set?
Thanks to the great work of @JaffaKetchup, package:http now supports the ability to abort requests.
You can read more about how to use the feature in the documentation.
Right now the feature is in beta and it would be great if everyone interested in this feature could try it out and report any issues that you find. You can do so by specifying the beta version in your pubspec.yaml (don't worry, that syntax will pick up newer versions as they appear):
http: ^1.5.0-beta
Reacted by TheEthicalBoy, Luka Stillingfleet, DanielJaramillo94, TiLogic, Tobias Marschall, Phuc Huynh, El, Tony Hart, Thomas Lüder, Luca Venir and 1 more
Activity
zichangg commentedon May 29, 2020
natebosch commentedon May 29, 2020
Here are a couple other options - I'm not advocating for these, just trying to brainstorm. Both of these are breaking changes for anyone with
implements http.Client.Allow passing a Future back to the client to cancel it. We'd have some state that lets us abort if you give us back the exact same instance.
Add a named argument to all the methods:
The latter could pair well with a
timeoutargument. Passingtimeout: Duration(seconds: 5)would have the same effect as passingabortOn: Future.delayed(Duration(seconds: 5))grouma commentedon Jun 1, 2020
I like the latter assuming a future that completes after the request has completed doesn't cause an issue.
liranzairi commentedon Aug 30, 2020
Hey, in my app I want to give the user an option to abort while uploading a file. I saw that dart:io is going to support it soon. However I use http package in my app so I looked here and saw this thread. Do you think you'll support it too, soon? Thanks
jakemac53 commentedon Aug 31, 2020
I think having an
abortmethod on the response itself is really the ideal design here, for a few reasons:This does get a bit trickier to implement - you are left with a few not so great options:
Futurewith some custom type, which beyond being considered an anti-pattern also raises some difficult questions around how you handle thecancelcase. I think for this you could just complete with a special type oferror, and not try to do whatCancelableOperationdoes (with a specialonCancelcallback that complicates error handling).CancelableOperation).natebosch commentedon Aug 31, 2020
The trickiest part of this is rolling it out, I think no matter what design we use it's going to be a breaking change for anyone with a class which
implements Client.natebosch commentedon Jan 6, 2021
I don't think that will be difficult in any case. We don't need an extra collection - we can handle this all at the point where we have the
HttpClientRequestor theHttpRequest.Attaching it to a
StreamedResponsehas the downside of pushing more users onto that API overhttp.get. I think cancellation (usually timeout) is a common enough use case that we want to support it on those APIs as well. Changing the return type fromFuturetoCancelablleOperationis more breaking, and I'm not entirely convinced one way or the other whether it's a better API if we were starting from scratch.I would expect that the typical case cancelations only happen after some async trigger either way. I think at most we could shave a microtask or 2, but I don't think that gives much power to typical usages. Which likely can't make many guarantees about behavior even if we give them a synchronous cancel.
natebosch commentedon Jan 6, 2021
I'm running with the
abortOnapproach for now.One thing that's tricky here, I didn't realize the
dart:ioimplementation causes thedonefuture to complete as an error as opposed to never completing. I'm pretty sure the implementation in the browsers wouldn't do that.I think it would be easier to build the error behavior in the browser than to build the never-complete behavior for
dart:iobut probably either is possible.I don't have a strong opinion between completing as error on abort, or never completing on abort. One nice thing about the error approach is that if you do want to forward an error object and stack trace through it's possible to do so.
cc @lrhn for opinions on completing as error vs never completing for aborted requests.
jakemac53 commentedon Jan 6, 2021
I really don't think
abortOnwith aFuturetype is the right api here... it has a lot of downsides. Specifically since you can't cancel the future at all I think it will be prone to memory leaks, hung processes on exit, and other similar issues.How about just supporting the
timeoutargument which we can ensure is implemented better (using a timer which we can cancel) as opposed to a delayed future?aytunch commentedon Jan 11, 2021
This is a must have feature. A lot of community backed packages are using this package at their core. And because there is not yet a abort functionality for downloads, there are huge amount of wasted data for Flutter users. This is really bad user experience when users check their data usage on their phones.
I am not sure why people are so concerned about breaking changes. Flutter is still new. Breaking changes are to be expected and for a core functionality like this, I am sure devs wont complain.
Imho what devs would really complain about could be a platform with APIs so hard to understand because they were patched for every new feature instead of getting redesigned. If we want Flutter to remain and feel fresh and different from the old and slow SDks then we have to live with breaking changes for a while.
Personally, the lack of aborting is a big deal for us because we have a video heavy app and we are using flutter_cache_manager to pre-download some of the videos in the list. If the user scrolls even further, we would like to abort the started downloads and start new ones. But for now we are stuck with 10's of started downloads which will be just byte waste.
fzyzcjy commentedon Aug 2, 2021
Hi, is there any updates after half a year?
Related: https://stackoverflow.com/questions/68615374/proper-way-of-setting-request-timeout-for-flutter-http-requests
mleonhard commentedon Aug 18, 2021
Related proposal: HttpClient deadline and retry (dart-lang/sdk#46557)
kevmoo commentedon Sep 13, 2021
@natebosch – what's the current story here?
natebosch commentedon Sep 13, 2021
This is still something we plan on looking at but we don't have a concrete plan.
36 remaining items
JaffaKetchup commentedon May 22, 2025
Looking at https://api.flutter.dev/flutter/dart-io/HttpClientRequest/abort.html:
done(which is returned byclose) is:So I would expect the abort to still do something until the response is available. In other words, I would expect it to be effective until we complete this line:
Therefore, I assume this means any response that the user manages to read for the IOClient will always be fully complete.
This is not the case for BrowserClient.
Does that make sense?
I can screen record to show you why I think that explains the behaviour I see.
brianquinlan commentedon May 22, 2025
You could just start writing integration tests to verify the behavior. I'd be happy to send you some code to get started.
JaffaKetchup commentedon May 22, 2025
Yeah, that might be helpful thanks.
brianquinlan commentedon May 22, 2025
I created a PR with some test ideas: #1777
There are some scenarios that I considered interesting in this file:
https://github.com/dart-lang/http/pull/1777/files#diff-1b0edc4ff03481f2fadadf18fbc7e6a828a0092275d13bd421c56b44b5eb3ca8R45
JaffaKetchup commentedon May 22, 2025
Ok, so some issues that seem to backup the difference in behaviour.
With the IOClient and "after response, client still useable" request:
triggeredAbortedRequestisfalse, and the test fails. IOClient does not throw and cannot throwAbortedRequestwhen reading the stream. It only happens onsend. Since we cancel aftersend, it does not cause any error to throw.The test is successful on BrowserClient.
This test seems potentially broken on both platforms:
Why would the last expect statement wait for the loop to reach 1000? Should I have changed something here?
I would also expect it to fail on IOClient in the same way as above.
This test fails on IOClient and succeeds on BrowserClient:
Expected: throws <Instance of 'AbortedRequest'> Actual: <Instance of 'Future<List<int>>'> Which: threw StateError:<Bad state: Too many elements> stack which is not an instance of 'AbortedRequest'I can't quite figure out what that response is saying. Too many elements? But anyway, same as before, IOClient only throws on
send.I don't think it's possible to change the behaviour of
IOClientto matchBrowserClientsince its under the control of dart:io. It might be possible to change the behaviour the other way to match, not sure the best way to do that. Is it even necessary?brianquinlan commentedon May 22, 2025
The test is trying to confirm that you don't get any more data after you aport the request.
...
You can by proxying the
StreamthatHttpClientuses. Pseudocode:JaffaKetchup commentedon May 23, 2025
@brianquinlan I'm not quite sure what that's trying to do.
From my understanding:
stream.pipe(ioRequest)This pumps the
stream(which is the request body) into the opened connection, then closes the request/connection.ioRequest, which happens withinpipe, it returns the HTTP responseSo I'm not sure what you meant by
ioRequest.listen- it can't be listened to.If abort is called after the pipe line, it is ineffective. Only after the pipe can we begin to read bytes. So I'm not sure it even makes sense to attempt to make the behaviour like
BrowserClient.JaffaKetchup commentedon May 23, 2025
I guess you could inject an error into the output byte stream where catchError is at the moment, is that what you were suggesting?
I'm not sure it makes sense though, it would be a lie (the whole response is always available at that point).
brianquinlan commentedon May 23, 2025
Sorry, I meant you can listen to
response.The entire premise of
package:httpis to provide a consistent interface across HTTP client implementations. That isn't always possible but, when it is possible (and I think that it is in this case), we try our best to make theClient's consistent.dart:ioHttpClientstreams the response (otherwise it would be impossible to do downloads that don't fit into memory).Let me know if you can stuck on this and I can propose some code - if you do that could you upload what you have on your PR with my conformance tests included?
Thanks again for working on this!
JaffaKetchup commentedon May 24, 2025
@brianquinlan
I've made
IOClientmostly work in the way we want.The limitation is that in the "while streaming response" test, the number of events received is larger than 1000 - it's always 1749. I would assume this is because of the way the events are emitted in batches. Even trying to use
takeUntilinstead of a custom implementation has the same issue, so I would assume it's unavoidable.May also need to tweak it a little more to respect
onListenon the controller etc. (and only start the subscription on the response then) so it doesn't waste memory, but I'm not sure if that's necessary.I'm struggling to make
BrowserClientmeet the "while streaming response" test. In the event of abortion, it just completes the stream without an error. Additionally, it somehow only counts up to 13! I guess the solution is the same as for IOClient, but it's a little but more difficult to work with.I might be able to take a look tomorrow, but if you wanted to have a look in the meantime, everything is up to date with your tests and my changes.
JaffaKetchup commentedon May 25, 2025
#1773 is (pretty much) ready!
brianquinlan commentedon Jun 3, 2025
#1773 is definitely moving us in the right direction but I'm worried that landing it will be hard because of the flaky failures in
IOClientand the work needed to makeRetryClientwork (let me know if you disagree @JaffaKetchup !)What
Clientimplementations do people care about? Because an alternative approach would be to incrementally support aborting requests i.e. we could start withBrowserClient,CupertinoHttpandCronetHttp.IOClientandRetryClientcould display a warning saying that they don't support aborting requests if theabortTriggerfuture is completed e.g.We could add support for
IOClientwhenever someone has the time to do so.Thoughts @natebosch @JaffaKetchup ?
JaffaKetchup commentedon Jun 3, 2025
Yeah, I can definitely see it might be tricky to get things working if I can't reproduce the issues :D
I've made a small change on #1773, could you run the tests again? It's ugly and I don't know if I expect it to work, but if it does, that confirms something(???) :D.
Unfortunately, the IO and browser clients are the ones I most care about - that's what we use by default in flutter_map (through the
Clientconstructor). We do useRetryClient- I could work around that in the meantime - but again, ideally, it would be implemented. And looking at the pub.dev stats, the vast majority of users seem to be using the default clients (idk about retry) - so not implementing it fully but landing the feature wouldn't seem quite right IMO.Could there be the option of disabling abortion for streamed requests for the time being - or simply refusing to abort requests while the data is being streamed in?
If it turns out we need to make a change to the Dart SDK, that complicates things ofc. I would hope that's not necessary though.
But as I'm very short on time for the next couple few weeks, and you are as well, I think leaving it for a few weeks is fine. Afterall, even if we managed to land it before your holiday somehow, I couldn't make good use of it for a few weeks. After that I'll have more time to figure things out (hopefully). Ofc if someone else wants it in the meantime... ;D
On a sort-of related note, I noticed https://pub.dev/packages/fetch_client. Doesn't the http implementation now use fetch as well? And after we've implemented this, wouldn't they both have the same feature set?
brianquinlan commentedon Jul 8, 2025
Thanks to the great work of @JaffaKetchup,
package:httpnow supports the ability to abort requests.You can read more about how to use the feature in the documentation.
Right now the feature is in beta and it would be great if everyone interested in this feature could try it out and report any issues that you find. You can do so by specifying the beta version in your
pubspec.yaml(don't worry, that syntax will pick up newer versions as they appear):