Skip to content

Commit 945840e

Browse files
committed
Added send progress to IOClient
1 parent 8ac84ef commit 945840e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkgs/http/lib/src/io_client.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,24 @@ class IOClient extends BaseClient {
6767
ioRequest.headers.set(name, value);
6868
});
6969

70-
var response = await stream.pipe(ioRequest) as HttpClientResponse;
70+
HttpClientResponse response;
71+
if (onSendProgress != null) {
72+
var loaded = 0;
73+
onSendProgress(loaded, request.contentLength);
74+
75+
await ioRequest.addStream(
76+
stream.map(
77+
(chunk) {
78+
loaded += chunk.length;
79+
onSendProgress(loaded, request.contentLength);
80+
return chunk;
81+
},
82+
),
83+
);
84+
response = await ioRequest.close();
85+
} else {
86+
response = await stream.pipe(ioRequest) as HttpClientResponse;
87+
}
7188

7289
var headers = <String, String>{};
7390
response.headers.forEach((key, values) {

0 commit comments

Comments
 (0)