Skip to content

Commit

Permalink
Avoid to send an extra request with empty buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Feb 28, 2023
1 parent b299c93 commit a9a6c97
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicInteger;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
Expand All @@ -11,6 +10,7 @@
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
import io.netty.handler.codec.http.multipart.FileUpload;
import io.netty.handler.codec.http.multipart.MemoryFileUpload;
Expand Down Expand Up @@ -148,25 +148,24 @@ public void run() {
throw new IllegalArgumentException("Wrong Vert.x context used for multipart upload. Expected: " + context +
", actual: " + Vertx.currentContext());
}
AtomicInteger counter = new AtomicInteger();
while (!ended) {
if (encoder.isChunked()) {
try {
HttpContent chunk = encoder.readChunk(ALLOC);
if (chunk == PausableHttpPostRequestEncoder.WAIT_MARKER) {
return; // resumption will be scheduled by encoder
}
ByteBuf content = chunk.content();
Buffer buff = Buffer.buffer(content);
counter.incrementAndGet();
boolean writable = pending.write(buff);
if (encoder.isEndOfInput()) {
} else if (chunk == LastHttpContent.EMPTY_LAST_CONTENT || encoder.isEndOfInput()) {
ended = true;
request = null;
encoder = null;
pending.write(InboundBuffer.END_SENTINEL);
} else if (!writable) {
break;
} else {
ByteBuf content = chunk.content();
Buffer buff = Buffer.buffer(content);
boolean writable = pending.write(buff);
if (!writable) {
break;
}
}
} catch (Exception e) {
handleError(e);
Expand Down

0 comments on commit a9a6c97

Please sign in to comment.