Skip to content

Commit e0b3615

Browse files
committed
adding chunk support for non-compressed request
Signed-off-by: Jitendra Kumar <[email protected]>
1 parent 303e408 commit e0b3615

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

client/rest/src/main/java/org/opensearch/client/RestClient.java

+25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.http.ConnectionClosedException;
3737
import org.apache.http.Header;
3838
import org.apache.http.HttpEntity;
39+
import org.apache.http.entity.HttpEntityWrapper;
3940
import org.apache.http.HttpHost;
4041
import org.apache.http.HttpRequest;
4142
import org.apache.http.HttpResponse;
@@ -644,6 +645,8 @@ private static HttpRequestBase addRequestBody(
644645
} else {
645646
entity = new ContentCompressingEntity(entity);
646647
}
648+
} else if (chunkedTransferEncodingEnabled) {
649+
entity = new ChunkedHttpEntity(entity);
647650
}
648651
((HttpEntityEnclosingRequestBase) httpRequest).setEntity(entity);
649652
} else {
@@ -1045,6 +1048,28 @@ public long getContentLength() {
10451048
}
10461049
}
10471050

1051+
public static class ChunkedHttpEntity extends HttpEntityWrapper {
1052+
/**
1053+
* Creates a {@link ChunkedHttpEntity} instance with the provided HTTP entity.
1054+
*
1055+
* @param entity the HTTP entity.
1056+
*/
1057+
public ChunkedHttpEntity(HttpEntity entity) {
1058+
super(entity);
1059+
}
1060+
1061+
/**
1062+
* A chunked entity requires transfer-encoding:chunked in http headers
1063+
* which requires isChunked to be true
1064+
*
1065+
* @return true
1066+
*/
1067+
@Override
1068+
public boolean isChunked() {
1069+
return true;
1070+
}
1071+
}
1072+
10481073
/**
10491074
* A ByteArrayOutputStream that can be turned into an input stream without copying the underlying buffer.
10501075
*/

client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public RestClientBuilder setCompressionEnabled(boolean compressionEnabled) {
240240
}
241241

242242
/**
243-
* Whether the REST client should use Transfer-Encoding: chunked for compress requests"
243+
* Whether the REST client should use Transfer-Encoding: chunked for requests or not"
244244
*
245245
* @param chunkedTransferEncodingEnabled flag for enabling Transfer-Encoding: chunked
246246
*/

0 commit comments

Comments
 (0)