Skip to content

Commit 377c6a8

Browse files
committed
Added send progress to IOClient
1 parent 962a91b commit 377c6a8

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
@@ -110,7 +110,24 @@ class IOClient extends BaseClient {
110110
ioRequest.headers.set(name, value);
111111
});
112112

113-
var response = await stream.pipe(ioRequest) as HttpClientResponse;
113+
HttpClientResponse response;
114+
if (onSendProgress != null) {
115+
var loaded = 0;
116+
onSendProgress(loaded, request.contentLength);
117+
118+
await ioRequest.addStream(
119+
stream.map(
120+
(chunk) {
121+
loaded += chunk.length;
122+
onSendProgress(loaded, request.contentLength);
123+
return chunk;
124+
},
125+
),
126+
);
127+
response = await ioRequest.close();
128+
} else {
129+
response = await stream.pipe(ioRequest) as HttpClientResponse;
130+
}
114131

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

0 commit comments

Comments
 (0)