Skip to content

(Web) StreamedRequest is a lie #1030

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

Closed
jezell opened this issue Oct 6, 2023 · 4 comments
Closed

(Web) StreamedRequest is a lie #1030

jezell opened this issue Oct 6, 2023 · 4 comments
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jezell
Copy link

jezell commented Oct 6, 2023

Steps to reproduce
Try to upload a large file using http.StreamedRequest with Flutter web (try 4GB). You'll always get an error:

The browser implementation of StreamedRequest always reads the entire request and response into memory. This doesn't have to happen as browsers have supported streaming via fetch for a very long time and makes flutter web totally broken if you need to deal with large files such as video, as this will cause the browser to complain that it can't allocate buffers that large: "RangeError: Array buffer allocation failed"

https://github.com/dart-lang/http/blob/master/pkgs/http/lib/src/browser_client.dart

StreamedRequest/StreamedResponse should be updated to use streaming fetch requests, as the current implementation defeats the point of why you would be using the streamed APIs in the first place. As of the moment, there's no way to upload large files to an S3 / Google cloud storage presigned url without throwing away the http package entirely on web. The whole point of this class is to stream, and it doesn't stream at all.

@jezell jezell added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 6, 2023
@jezell jezell changed the title StreamedRequest is a lie (Web) StreamedRequest is a lie Oct 6, 2023
@brianquinlan
Copy link
Collaborator

You could consider using package:fetch_client - it uses the same Client interface as BrowserClient and supports streaming.

We are currently working on better documentation that recommends appropriate Client implementations.

@jezell
Copy link
Author

jezell commented Oct 6, 2023

@brianquinlan that is a terrible answer. the standard http package should use fetch for the streaming request and response when it is available. I shouldn't have to write platform specific code to do streaming because the built in http package is based on tech from IE 5.5. That defeats the whole point of having the cross platform http package in the first place.

@jezell
Copy link
Author

jezell commented Oct 6, 2023

@brianquinlan StreamedRequest and StreamedResponse exist to stream. They work on every platform except web. They should work on web. There is no good reason they can't. It doesn't even need to be a breaking change and it has been a supported and standard part of the web platform for a while.

@natebosch
Copy link
Member

Continued discussion about moving to fetch should happen in #595

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants