Skip to content

Commit aa536dd

Browse files
committed
Update progress during upload large bodies
Motivation: org.asynchttpclient.netty.request.body.BodyChunkedInput does not update progress member, it stays zero whole time. Thus org.asynchttpclient.handler.onContentWriteProgress#onContentWriteProgress receives zeroes in ammount and current parameters. Users sees data is being sent but has no information about exact amount of data has been written to channel. Modifications: org.asynchttpclient.netty.request.body.BodyChunkedInput was modified to update progress. org.asynchttpclient.netty.request.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 f73c5b3 commit aa536dd

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)