diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java index ddf3760da7b39..61277a7853982 100644 --- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java +++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java @@ -110,6 +110,14 @@ static Object toHttpResponse(HttpServerResponse response, Message message, Heade 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) { @@ -119,6 +127,15 @@ static Object toHttpResponse(HttpServerResponse response, Message message, Heade 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