Fix automatically set content-length or chunked on platform-http replies
@@ -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) {
@@ -228,6 +236,18 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
return body;
}
+ /*
+ * 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
