This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push: new 80665b0 Fix #301: Auto-set content-length or chunked transfer encoding new ae0001f Merge pull request #302 from nicolaferraro/fix-transfer-encoding 80665b0 is described below commit 80665b0cdb5249938566ec117145a8c11556b1e5 Author: Nicola Ferraro <ni.ferr...@gmail.com> AuthorDate: Wed Apr 15 15:47:11 2020 +0200 Fix #301: Auto-set content-length or chunked transfer encoding --- .../k/http/engine/RuntimePlatformHttpConsumer.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java index 300fe91..bb44864 100644 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java +++ b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java @@ -200,6 +200,14 @@ public class RuntimePlatformHttpConsumer extends DefaultConsumer { ExchangeHelper.setFailureHandled(exchange); } + // set the content-length if it can be determined, or chunked encoding + final Integer length = determineContentLength(exchange, body); + if (length != null) { + response.putHeader("Content-Length", String.valueOf(length)); + } else { + response.setChunked(true); + } + // set the content type in the response. final String contentType = MessageHelper.getContentType(message); if (contentType != null) { @@ -209,6 +217,15 @@ public class RuntimePlatformHttpConsumer extends DefaultConsumer { return body; } + static Integer determineContentLength(Exchange camelExchange, Object body) { + if (body instanceof byte[]) { + return ((byte[]) body).length; + } else if (body instanceof ByteBuffer) { + return ((ByteBuffer) body).remaining(); + } + return null; + } + /* * Copied from org.apache.camel.http.common.DefaultHttpBinding.determineResponseCode(Exchange, Object) * If DefaultHttpBinding.determineResponseCode(Exchange, Object) is moved to a module without the servlet-api