Skip to content

Commit 9bb793e

Browse files
committed
Content-Length header should be honored when passing an InputStream, close #1440
Motivation: When Content-Length is known beforehand, we shouldn’t ignore it and enforce chunked transfer-encoding. Modification: Honor Content-Length request header. Result: Chunked transfer-encoding is no longer enforced
1 parent e0b097d commit 9bb793e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.netty.handler.codec.http.HttpVersion;
3030
import io.netty.handler.codec.http.cookie.ClientCookieEncoder;
3131

32+
import java.io.InputStream;
3233
import java.nio.charset.Charset;
3334

3435
import org.asynchttpclient.AsyncHttpClientConfig;
@@ -81,7 +82,9 @@ private NettyBody body(Request request) {
8182
nettyBody = new NettyByteBufferBody(request.getByteBufferData());
8283

8384
} else if (request.getStreamData() != null) {
84-
nettyBody = new NettyInputStreamBody(request.getStreamData());
85+
InputStream is = request.getStreamData();
86+
String contentLengthHeader = request.getHeaders().get(CONTENT_LENGTH);
87+
nettyBody = contentLengthHeader != null ? new NettyInputStreamBody(is, Long.parseLong(contentLengthHeader)) : new NettyInputStreamBody(is);
8588

8689
} else if (isNonEmpty(request.getFormParams())) {
8790
CharSequence contentTypeOverride = request.getHeaders().contains(CONTENT_TYPE) ? null : HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED;

0 commit comments

Comments
 (0)