From 1d8a6308489d567a30a87b042315ddc8a34c09f8 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 25 Jul 2017 22:29:46 +0200 Subject: [PATCH] User defined Content-Length request header should be honored, close #1440 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation: When Content-Length is known beforehand, we shouldn’t ignore it and enforce chunked transfer-encoding. Modification: Honor Content-Length request header when it's defined. Result: Chunked transfer-encoding is no longer enforced --- .../netty/request/NettyRequestFactory.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java index 67e66288ca..b125d35061 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java @@ -177,10 +177,12 @@ public NettyRequest newNettyRequest(Request request, boolean forceConnect, Proxy } if (body != null) { - if (body.getContentLength() < 0) { - headers.set(TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); - } else { - headers.set(CONTENT_LENGTH, body.getContentLength()); + if (!headers.contains(CONTENT_LENGTH)) { + if (body.getContentLength() < 0) { + headers.set(TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); + } else { + headers.set(CONTENT_LENGTH, body.getContentLength()); + } } if (body.getContentTypeOverride() != null) {