Skip to content

Commit

Permalink
Content-Length header should be honored when passing an InputStream, c…
Browse files Browse the repository at this point in the history
…lose #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
  • Loading branch information
slandelle committed Jul 25, 2017
1 parent e0b097d commit 9bb793e
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.cookie.ClientCookieEncoder;

import java.io.InputStream;
import java.nio.charset.Charset;

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

} else if (request.getStreamData() != null) {
nettyBody = new NettyInputStreamBody(request.getStreamData());
InputStream is = request.getStreamData();
String contentLengthHeader = request.getHeaders().get(CONTENT_LENGTH);
nettyBody = contentLengthHeader != null ? new NettyInputStreamBody(is, Long.parseLong(contentLengthHeader)) : new NettyInputStreamBody(is);

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

0 comments on commit 9bb793e

Please sign in to comment.