Skip to content

Commit 4efd506

Browse files
committed
HTTPRequestProcessor: Reduced buffer allocations for chunked encoding
This reduces the allocation / throw away of buffers when the chunk sizes are beyond our maximum buffer size.
1 parent 9b0b2e6 commit 4efd506

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

protocol/src/main/java/org/threadly/litesockets/protocols/http/request/HTTPRequestProcessor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ private boolean parseChunkData() {
265265
sendDuplicateBBtoListeners(chunkedBB);
266266
int remaining = Math.min(((int)bodySize) - currentBodySize, MAX_CHUNK_SIZE);
267267
if (remaining > 0) {
268-
chunkedBB = ByteBuffer.allocate(remaining);
268+
chunkedBB.clear();
269+
if (remaining < chunkedBB.capacity()) {
270+
chunkedBB.limit(remaining);
271+
} // it should not be possible for remaining to be larger than the buffer size
269272
} else {
270273
chunkedBB = null;
271274
}
@@ -306,7 +309,10 @@ public void reset(Throwable t) {
306309
this.request = null;
307310
this.currentBodySize = 0;
308311
this.bodySize = 0;
309-
this.isChunked = false;
312+
if (isChunked) {
313+
isChunked = false;
314+
chunkedBB = null;
315+
}
310316
}
311317

312318
/**

0 commit comments

Comments
 (0)