dart-lang / http

A composable API for making HTTP requests in Dart.
https://pub.dev/packages/http
BSD 3-Clause "New" or "Revised" License
1.01k stars 352 forks source link

Stream buffering in cupertino_http StreamedRequest #997

Open Vovcharaa opened 1 year ago

Vovcharaa commented 1 year ago

Related https://github.com/dart-lang/http/issues/974 StreamQueue is buffering everything it can consume before sending it to the remote. This still prevents tracking upload progress or sending large files. https://github.com/dart-lang/http/blob/b2067710f88980fc0fee43ec3380bce089f001db/pkgs/cupertino_http/lib/src/cupertino_api.dart#L124-L127 https://github.com/dart-lang/http/blob/b2067710f88980fc0fee43ec3380bce089f001db/pkgs/cupertino_http/lib/src/cupertino_client.dart#L219-L228

Vovcharaa commented 1 year ago

@brianquinlan Perhaps, I misunderstood how StreamController(sync: true) is working. I want to be able to send data into the StreamingRequest sink with knowledge of how much of the data is sent to the server. But I can't track progress if something is buffering my data before it is sent to the server. When I am sending chunks of data with an artificial delay between them, I can see these chunks on the server as they are sent. So streaming request is definitely working, but not as I expected it will be. Is it actually possible to track uploading progress in StreamedRequest?

brianquinlan commented 1 year ago

From https://github.com/dart-lang/http/issues/974: Could you include the stream that you are sending? AFAIK, _hasData is only buffering the first non-empty List in the stream.

_streamToNSInputStream is only providing data when requested to by the Apple's client implementation and is, in my experience, providing less data than requested.

I don't think that you can accurately track uploading progress using StreamedRequest unless the request is "large" and the input stream emits List<int> whose size is significantly less than the total request size.

How much data are you sending on how many List<int>s are in your Stream?