Skip to content

Commit 43cff3a

Browse files
odiszapcslandelle
authored andcommitted
Update progress during upload large bodies, close AsyncHttpClient#728
Motivation: `BodyChunkedInput` does not update progress member, it always stays zero. Thus `ProgressAsyncHandler#onContentWriteProgress` receives zeroes in amount and current parameters. Users sees data is being sent but has no information about exact amount of data has been written to channel. Modifications: `BodyChunkedInput` was modified to update progress. `WriteProgressListener` was modified to ignore zero progress. It happens due to non-blocking nature of network writes. We just ignore callbacks when there was no progress at all. Result: Progress is updated each time bytes are phisically written to channel. Callbacks are triggered with actual amount of data written.
1 parent 79016a7 commit 43cff3a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

client/src/main/java/org/asynchttpclient/netty/request/WriteProgressListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public void operationProgressed(ChannelProgressiveFuture f, long progress, long
4545
if (total < 0) {
4646
total = expectedTotal;
4747
}
48-
progressAsyncHandler.onContentWriteProgress(progress - lastLastProgress, progress, total);
48+
if (progress != lastLastProgress) {
49+
progressAsyncHandler.onContentWriteProgress(progress - lastLastProgress, progress, total);
50+
}
4951
}
5052
}
5153
}

client/src/main/java/org/asynchttpclient/netty/request/body/BodyChunkedInput.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public ByteBuf readChunk(ByteBufAllocator alloc) throws Exception {
5757

5858
ByteBuf buffer = alloc.buffer(chunkSize);
5959
Body.BodyState state = body.transferTo(buffer);
60+
progress += buffer.writerIndex();
6061
switch (state) {
6162
case STOP:
6263
endOfInput = true;

0 commit comments

Comments
 (0)