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

davsclaus pushed a commit to branch camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.22.x by this push:
     new a8714ad3778d CAMEL-24424: camel-vertx-http - apply the outbound header 
filter on the REST producer
a8714ad3778d is described below

commit a8714ad3778dca3c29fc526a7aae2ffd6c77bd3c
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Sep 8 20:52:47 2026 +0200

    CAMEL-24424: camel-vertx-http - apply the outbound header filter on the 
REST producer
    
    Backport of #26183 to camel-4.22.x.
    
    VertxHttpRestHeaderFilterStrategy.applyFilterToCamelHeaders() delegated to
    super.applyFilterToExternalHeaders() - the inbound rules - while 
implementing the
    outbound direction, so the out filter installed by 
VertxHttpHeaderFilterStrategy was
    never applied on a REST producer. A message header named Content-Length,
    Transfer-Encoding, Host or Connection was therefore copied verbatim onto 
the outgoing
    request, which can desynchronise a downstream parser. The sibling REST 
strategies in
    camel-http-common, camel-netty-http and camel-undertow all delegate to the 
matching
    super method; vertx-http was the only one left with the mismatch, present 
since the
    component was added in CAMEL-15283.
    
    VertxHttpRestProducerHeaderFilterTest drives a rest:get producer bound to 
vertx-http
    against an undertow test server and asserts what reaches the wire, 
including that the
    request Content-Type still propagates.
    
    Closes #26209
    
    Co-authored-by: Claude <[email protected]>
---
 components/camel-vertx/camel-vertx-http/pom.xml    |  5 ++
 .../http/VertxHttpRestHeaderFilterStrategy.java    |  2 +-
 .../VertxHttpRestProducerHeaderFilterTest.java     | 81 ++++++++++++++++++++++
 3 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/components/camel-vertx/camel-vertx-http/pom.xml 
b/components/camel-vertx/camel-vertx-http/pom.xml
index 983ce614ddc1..d41cf103eb0b 100644
--- a/components/camel-vertx/camel-vertx-http/pom.xml
+++ b/components/camel-vertx/camel-vertx-http/pom.xml
@@ -60,6 +60,11 @@
             <artifactId>camel-http</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-rest</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-undertow</artifactId>
diff --git 
a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpRestHeaderFilterStrategy.java
 
b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpRestHeaderFilterStrategy.java
index 87196d0869d0..8489945cf34f 100644
--- 
a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpRestHeaderFilterStrategy.java
+++ 
b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpRestHeaderFilterStrategy.java
@@ -32,7 +32,7 @@ public class VertxHttpRestHeaderFilterStrategy extends 
VertxHttpHeaderFilterStra
 
     @Override
     public boolean applyFilterToCamelHeaders(String headerName, Object 
headerValue, Exchange exchange) {
-        boolean answer = super.applyFilterToExternalHeaders(headerName, 
headerValue, exchange);
+        boolean answer = super.applyFilterToCamelHeaders(headerName, 
headerValue, exchange);
 
         return filterCheck(templateUri, queryParameters, headerName, answer);
     }
diff --git 
a/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpRestProducerHeaderFilterTest.java
 
b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpRestProducerHeaderFilterTest.java
new file mode 100644
index 000000000000..fc6190cab638
--- /dev/null
+++ 
b/components/camel-vertx/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpRestProducerHeaderFilterTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.vertx.http;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Message;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+public class VertxHttpRestProducerHeaderFilterTest extends 
VertxHttpTestSupport {
+
+    @Test
+    public void testRestProducerAppliesTheOutboundFilter() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:input");
+        mock.expectedMessageCount(1);
+
+        Map<String, Object> headers = new HashMap<>();
+        headers.put("id", "123");
+        headers.put("Via", "1.1 rogue-proxy");
+        headers.put("Cache-Control", "no-cache");
+        headers.put("Content-Type", "application/json");
+        headers.put("X-Custom", "custom-value");
+
+        String out = template.requestBodyAndHeaders("direct:start", null, 
headers, String.class);
+        assertEquals("Hello World", out);
+
+        MockEndpoint.assertIsSatisfied(context);
+
+        Message received = mock.getReceivedExchanges().get(0).getMessage();
+        // excluded on the outbound direction by the common HTTP filter set, 
so they must not reach the wire
+        assertNull(received.getHeader("Via"));
+        assertNull(received.getHeader("Cache-Control"));
+        // already consumed by the uri template, so it must not be sent as an 
HTTP header as well
+        assertNull(received.getHeader("id"));
+        // not filtered on either direction
+        assertEquals("custom-value", received.getHeader("X-Custom"));
+        // Content-Type is in the common HTTP filter set, but the producer 
sets it explicitly from the exchange
+        // content type before the filter loop runs, so it must still reach 
the server
+        assertEquals("application/json", received.getHeader("Content-Type"));
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                restConfiguration()
+                        .producerComponent("vertx-http")
+                        .host("localhost").port(getPort());
+
+                from("direct:start")
+                        .to("rest:get:foo/{id}");
+
+                from(getTestServerUri() + "/foo/123")
+                        .to("mock:input")
+                        .setBody(constant("Hello World"));
+            }
+        };
+    }
+}

Reply via email to