This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new ea5144c  Fix #1288: automatically set content-length or chunked on 
platform-http replies
ea5144c is described below

commit ea5144c2cb3d5e12d9018c1dacd1dda578c843de
Author: Nicola Ferraro <ni.ferr...@gmail.com>
AuthorDate: Mon Jun 1 12:25:13 2020 +0200

    Fix #1288: automatically set content-length or chunked on platform-http 
replies
---
 .../http/runtime/QuarkusPlatformHttpConsumer.java    | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git 
a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
 
b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
index 6fa7258..087ed58 100644
--- 
a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
+++ 
b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java
@@ -219,6 +219,14 @@ public class QuarkusPlatformHttpConsumer 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) {
@@ -229,6 +237,18 @@ public class QuarkusPlatformHttpConsumer extends 
DefaultConsumer {
     }
 
     /*
+     * Copied from 
org.apache.camel.component.platform.http.vertx.VertxPlatformHttpSupport.determineContentLength(Exchange,
 Object)
+     */
+    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
      * dependency we could eventually consume it from there.

Reply via email to