This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 90713cadf385 CAMEL-23936: Fix logHttpActivity losing Content-Encoding
on gzip responses
90713cadf385 is described below
commit 90713cadf385f182a9b675ea4f901858220df73e
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jul 8 15:21:38 2026 +0200
CAMEL-23936: Fix logHttpActivity losing Content-Encoding on gzip responses
When logHttpActivity is enabled and the HTTP server returns a gzip-encoded
response, the replacement ByteArrayEntity created during logging did not
preserve the original Content-Encoding, causing HttpClient's
ContentCompressionExec to skip decompression. Pass the content encoding
to the ByteArrayEntity constructor.
Closes #24506
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../http/LoggingHttpActivityListener.java | 2 +-
.../camel/component/http/HttpCompressionTest.java | 2 +-
.../http/HttpLoggingActivityGzipTest.java | 56 ++++++++++++++++++++++
3 files changed, 58 insertions(+), 2 deletions(-)
diff --git
a/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
index 22a5645b3477..e37fdcf0ab84 100644
---
a/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
+++
b/components/camel-http/src/main/java/org/apache/camel/component/http/LoggingHttpActivityListener.java
@@ -205,7 +205,7 @@ public class LoggingHttpActivityListener extends
ServiceSupport implements Camel
byte[] arr = bos.toByteArray();
// ByteArrayEntity close() is a NOOP.
Additionally
// the stream must be closed by client
(request/response in our case).
- e = new ByteArrayEntity(arr, ct); // NOSONAR
+ e = new ByteArrayEntity(arr, ct, ce); //
NOSONAR
if (request instanceof HttpEntityContainer ec)
{
ec.setEntity(e);
} else if (response instanceof
HttpEntityContainer ec) {
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpCompressionTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpCompressionTest.java
index 697861ab9d1d..a0127fbbd55c 100644
---
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpCompressionTest.java
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpCompressionTest.java
@@ -59,7 +59,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class HttpCompressionTest extends BaseHttpTest {
- private HttpServer localServer;
+ protected HttpServer localServer;
@Override
public void setupResources() throws Exception {
diff --git
a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpLoggingActivityGzipTest.java
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpLoggingActivityGzipTest.java
new file mode 100644
index 000000000000..81709e6340a1
--- /dev/null
+++
b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpLoggingActivityGzipTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.http;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.hc.core5.http.HttpStatus;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class HttpLoggingActivityGzipTest extends HttpCompressionTest {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ HttpComponent http = context.getComponent("http", HttpComponent.class);
+ http.setLogHttpActivity(true);
+ return context;
+ }
+
+ @Test
+ public void compressedHttpPostWithLogging() {
+ Exchange exchange = template.request(
+ "http://localhost:" + localServer.getLocalPort() + "/",
exchange1 -> {
+ exchange1.getIn().setHeader(Exchange.CONTENT_TYPE,
"text/plain");
+ exchange1.getIn().setHeader(Exchange.CONTENT_ENCODING,
"gzip");
+ exchange1.getIn().setBody(getBody());
+ });
+
+ assertNotNull(exchange);
+ assertNull(exchange.getException());
+
+ Message out = exchange.getMessage();
+ assertNotNull(out);
+ assertEquals(HttpStatus.SC_OK,
out.getHeaders().get(Exchange.HTTP_RESPONSE_CODE));
+ assertBody(out.getBody(String.class));
+ }
+}