Skip to content

Commit

Permalink
adding chunk support for non-compressed request
Browse files Browse the repository at this point in the history
Signed-off-by: Jitendra Kumar <jkjitend@amazon.com>
  • Loading branch information
kumjiten committed Jul 1, 2022
1 parent 303e408 commit e0b3615
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions client/rest/src/main/java/org/opensearch/client/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.http.ConnectionClosedException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
Expand Down Expand Up @@ -644,6 +645,8 @@ private static HttpRequestBase addRequestBody(
} else {
entity = new ContentCompressingEntity(entity);
}
} else if (chunkedTransferEncodingEnabled) {
entity = new ChunkedHttpEntity(entity);
}
((HttpEntityEnclosingRequestBase) httpRequest).setEntity(entity);
} else {
Expand Down Expand Up @@ -1045,6 +1048,28 @@ public long getContentLength() {
}
}

public static class ChunkedHttpEntity extends HttpEntityWrapper {
/**
* Creates a {@link ChunkedHttpEntity} instance with the provided HTTP entity.
*
* @param entity the HTTP entity.
*/
public ChunkedHttpEntity(HttpEntity entity) {
super(entity);
}

/**
* A chunked entity requires transfer-encoding:chunked in http headers
* which requires isChunked to be true
*
* @return true
*/
@Override
public boolean isChunked() {
return true;
}
}

/**
* A ByteArrayOutputStream that can be turned into an input stream without copying the underlying buffer.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public RestClientBuilder setCompressionEnabled(boolean compressionEnabled) {
}

/**
* Whether the REST client should use Transfer-Encoding: chunked for compress requests"
* Whether the REST client should use Transfer-Encoding: chunked for requests or not"
*
* @param chunkedTransferEncodingEnabled flag for enabling Transfer-Encoding: chunked
*/
Expand Down

0 comments on commit e0b3615

Please sign in to comment.