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

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

commit fbb811d0c0ebc38d3e13f5910e24b32b2591b21f
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon May 5 09:41:28 2025 +0200

    CAMEL-21902: camel-core: HeaderFilterStrategy should default be case 
insensitive. Remove Camel v1 style header
---
 .../cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java   |  4 +-
 .../http/common/HttpHeaderFilterStrategyTest.java  |  4 +-
 .../http/NettyHttpHeaderFilterStrategyTest.java    |  4 +-
 .../impl/DefaultHeaderFilterStrategyTest.java      | 49 ++++++++++++++++++----
 .../camel/bean/DefaultHeaderFilterStrategy.json    |  2 +-
 .../camel/support/DefaultHeaderFilterStrategy.java | 17 ++++----
 .../ROOT/pages/camel-4x-upgrade-guide-4_12.adoc    |  9 ++++
 7 files changed, 66 insertions(+), 23 deletions(-)

diff --git 
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
 
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
index 69ba93a1e23..f6149cce88f 100644
--- 
a/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
+++ 
b/components/camel-cxf/camel-cxf-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsHeaderFilterStrategyTest.java
@@ -38,9 +38,9 @@ public class CxfRsHeaderFilterStrategyTest {
         assertTrue(filter.applyFilterToCamelHeaders(Exchange.CHARSET_NAME, 
"just a test", null), "Get a wrong filtered result");
         
assertTrue(filter.applyFilterToCamelHeaders(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS,
 "just a test", null),
                 "Get a wrong filtered result");
-        
assertTrue(filter.applyFilterToCamelHeaders("org.apache.camel.such.Header", 
"just a test", null),
+        assertTrue(filter.applyFilterToCamelHeaders("CamelHeader", "just a 
test", null),
                 "Get a wrong filtered result");
-        assertTrue(filter.applyFilterToCamelHeaders("camel.result", "just a 
test", null), "Get a wrong filtered result");
+        assertTrue(filter.applyFilterToCamelHeaders("CamelResult", "just a 
test", null), "Get a wrong filtered result");
 
         assertFalse(filter.applyFilterToCamelHeaders("MyWorld", "just a test", 
null), "Get a wrong filtered result");
     }
diff --git 
a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java
 
b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java
index 0865a150078..07a5804c77e 100644
--- 
a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java
+++ 
b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java
@@ -62,7 +62,7 @@ public class HttpHeaderFilterStrategyTest extends 
CamelTestSupport {
 
         // any Camel header should be filtered
         assertTrue(filter.applyFilterToExternalHeaders("CamelHeader", "test", 
exchange));
-        
assertTrue(filter.applyFilterToExternalHeaders("org.apache.camel.header", 
"test", exchange));
+        assertTrue(filter.applyFilterToExternalHeaders("CAMELHeader", "test", 
exchange));
 
         assertFalse(filter.applyFilterToExternalHeaders("notFilteredHeader", 
"test", exchange));
 
@@ -97,7 +97,7 @@ public class HttpHeaderFilterStrategyTest extends 
CamelTestSupport {
 
         // any Camel header should be filtered
         assertTrue(filter.applyFilterToCamelHeaders("CamelHeader", "test", 
exchange));
-        assertTrue(filter.applyFilterToCamelHeaders("org.apache.camel.header", 
"test", exchange));
+        assertTrue(filter.applyFilterToCamelHeaders("CAMELHeader", "test", 
exchange));
 
         assertFalse(filter.applyFilterToCamelHeaders("notFilteredHeader", 
"test", exchange));
 
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategyTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategyTest.java
index 5f12777fd38..07cce9cea30 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategyTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategyTest.java
@@ -63,7 +63,7 @@ public class NettyHttpHeaderFilterStrategyTest {
 
         // any Camel header should be filtered
         assertTrue(filter.applyFilterToExternalHeaders("CamelHeader", "test", 
exchange));
-        
assertTrue(filter.applyFilterToExternalHeaders("org.apache.camel.header", 
"test", exchange));
+        assertTrue(filter.applyFilterToExternalHeaders("CAMELHeader", "test", 
exchange));
 
         assertFalse(filter.applyFilterToExternalHeaders("notFilteredHeader", 
"test", exchange));
 
@@ -98,7 +98,7 @@ public class NettyHttpHeaderFilterStrategyTest {
 
         // any Camel header should be filtered
         assertTrue(filter.applyFilterToCamelHeaders("CamelHeader", "test", 
exchange));
-        assertTrue(filter.applyFilterToCamelHeaders("org.apache.camel.header", 
"test", exchange));
+        assertTrue(filter.applyFilterToCamelHeaders("CAMELHeader", "test", 
exchange));
 
         assertFalse(filter.applyFilterToCamelHeaders("notFilteredHeader", 
"test", exchange));
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
index cb00968b24d..5e26dfeca8c 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultHeaderFilterStrategyTest.java
@@ -40,8 +40,9 @@ public class DefaultHeaderFilterStrategyTest extends 
ContextTestSupport {
         comp.setLowerCase(true);
         assertTrue(comp.isLowerCase());
 
-        comp.setCaseInsensitive(true);
         assertTrue(comp.isCaseInsensitive());
+        comp.setCaseInsensitive(false);
+        assertFalse(comp.isCaseInsensitive());
 
         comp.setFilterOnMatch(false);
         assertFalse(comp.isFilterOnMatch());
@@ -74,6 +75,40 @@ public class DefaultHeaderFilterStrategyTest extends 
ContextTestSupport {
         assertTrue(comp.applyFilterToExternalHeaders("foo", "cheese", 
exchange));
     }
 
+    @Test
+    public void testInFilterCaseSensitive() {
+        DefaultHeaderFilterStrategy comp = new DefaultHeaderFilterStrategy();
+        comp.setCaseInsensitive(false);
+
+        Set<String> set = new HashSet<>();
+        set.add("foo");
+        comp.setInFilter(set);
+
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setHeader("bar", 123);
+        exchange.getIn().setHeader("FOO", "cheese");
+
+        assertFalse(comp.applyFilterToExternalHeaders("bar", 123, exchange));
+        assertFalse(comp.applyFilterToExternalHeaders("FOO", "cheese", 
exchange));
+    }
+
+    @Test
+    public void testInFilterCaseInsensitive() {
+        DefaultHeaderFilterStrategy comp = new DefaultHeaderFilterStrategy();
+        comp.setCaseInsensitive(true);
+
+        Set<String> set = new HashSet<>();
+        set.add("foo");
+        comp.setInFilter(set);
+
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setHeader("bar", 123);
+        exchange.getIn().setHeader("FOO", "cheese");
+
+        assertFalse(comp.applyFilterToExternalHeaders("bar", 123, exchange));
+        assertTrue(comp.applyFilterToExternalHeaders("FOO", "cheese", 
exchange));
+    }
+
     @Test
     public void testOutFilterDefaultHeaderFilterStrategy() {
         DefaultHeaderFilterStrategy comp = new DefaultHeaderFilterStrategy();
@@ -147,14 +182,14 @@ public class DefaultHeaderFilterStrategyTest extends 
ContextTestSupport {
         exchange.getIn().setHeader("foo", "cheese");
         exchange.getIn().setHeader("CamelName", "Apache Camel");
         exchange.getIn().setHeader("camelVersion", "3.7");
-        exchange.getIn().setHeader("org.apache.camel.id", "foo");
+        exchange.getIn().setHeader("camelID", "foo");
 
         assertFalse(comp.applyFilterToCamelHeaders("bar", 123, exchange));
         assertFalse(comp.applyFilterToCamelHeaders("foo", "cheese", exchange));
         assertTrue(comp.applyFilterToCamelHeaders("CamelName", "Apache Camel", 
exchange));
         assertTrue(comp.applyFilterToCamelHeaders("camelVersion", "3.7", 
exchange));
         assertTrue(comp.applyFilterToCamelHeaders("camelNextVersion", "3.8", 
exchange));
-        
assertTrue(comp.applyFilterToCamelHeaders("org.apache.camel.component.seda.queueSize",
 "123", exchange));
+        assertTrue(comp.applyFilterToCamelHeaders("CamelSedaQeueSize", "123", 
exchange));
     }
 
     @Test
@@ -167,12 +202,12 @@ public class DefaultHeaderFilterStrategyTest extends 
ContextTestSupport {
         exchange.getIn().setHeader("bar", 123);
         exchange.getIn().setHeader("foo", "cheese");
         exchange.getIn().setHeader("CamelVersion", "3.7");
-        exchange.getIn().setHeader("org.apache.camel.component.jetty.session", 
"true");
+        exchange.getIn().setHeader("camelJettySession", "true");
 
         assertFalse(comp.applyFilterToExternalHeaders("bar", 123, exchange));
         assertFalse(comp.applyFilterToExternalHeaders("foo", "cheese", 
exchange));
         assertTrue(comp.applyFilterToExternalHeaders("CamelVersion", "3.7", 
exchange));
-        
assertTrue(comp.applyFilterToExternalHeaders("org.apache.camel.component.jetty.session",
 "true", exchange));
+        assertTrue(comp.applyFilterToExternalHeaders("camelJETTYSession", 
"true", exchange));
     }
 
     @Test
@@ -186,7 +221,7 @@ public class DefaultHeaderFilterStrategyTest extends 
ContextTestSupport {
         exchange.getIn().setHeader("bar", 123);
         exchange.getIn().setHeader("foo", "cheese");
         exchange.getIn().setHeader("caMElVersion", "3.7");
-        exchange.getIn().setHeader("org.apache.CAMEL.component.jetty.session", 
"true");
+        exchange.getIn().setHeader("CAMELJETTYSession", "true");
 
         assertTrue(comp.applyFilterToExternalHeaders("caMElVersion", 123, 
exchange));
         assertTrue(comp.applyFilterToExternalHeaders("cAmelResponseCode", 503, 
exchange));
@@ -194,7 +229,7 @@ public class DefaultHeaderFilterStrategyTest extends 
ContextTestSupport {
         assertFalse(comp.applyFilterToExternalHeaders("bar", 123, exchange));
         assertFalse(comp.applyFilterToExternalHeaders("foo", "cheese", 
exchange));
         assertTrue(comp.applyFilterToExternalHeaders("CamelVersion", "3.7", 
exchange));
-        
assertTrue(comp.applyFilterToExternalHeaders("org.apache.camel.component.jetty.session",
 "true", exchange));
+        assertTrue(comp.applyFilterToExternalHeaders("CamelJettySession", 
"true", exchange));
     }
 
 }
diff --git 
a/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/DefaultHeaderFilterStrategy.json
 
b/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/DefaultHeaderFilterStrategy.json
index e370a322e87..aed9f7d99b8 100644
--- 
a/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/DefaultHeaderFilterStrategy.json
+++ 
b/core/camel-support/src/generated/resources/META-INF/services/org/apache/camel/bean/DefaultHeaderFilterStrategy.json
@@ -10,7 +10,7 @@
     "groupId": "org.apache.camel",
     "artifactId": "camel-support",
     "version": "4.12.0-SNAPSHOT",
-    "properties": { "inFilter": { "index": 0, "kind": "property", 
"displayName": "In Filter", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Sets the in direction filter set. The in direction is referred 
to copying headers from an external message to a Camel message. Multiple 
patterns can be separated by comma" }, "outFilter": { "index": 1, "kind": 
"property", "displayName": "Out Filter", "req [...]
+    "properties": { "inFilter": { "index": 0, "kind": "property", 
"displayName": "In Filter", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Sets the in direction filter set. The in direction is referred 
to copying headers from an external message to a Camel message. Multiple 
patterns can be separated by comma" }, "outFilter": { "index": 1, "kind": 
"property", "displayName": "Out Filter", "req [...]
   }
 }
 
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
index 28ef62125e5..f8ac8f3e21c 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultHeaderFilterStrategy.java
@@ -42,17 +42,17 @@ import org.apache.camel.spi.Metadata;
 public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
 
     /**
-     * A filter pattern that only accepts keys starting with <tt>Camel</tt> or 
<tt>org.apache.camel.</tt>
+     * A filter pattern that only accepts keys starting with <tt>Camel</tt>.
      *
      * @deprecated use {@link #CAMEL_FILTER_STARTS_WITH}
      */
     @Deprecated(since = "3.9.0")
-    public static final Pattern CAMEL_FILTER_PATTERN = 
Pattern.compile("(?i)(Camel|org\\.apache\\.camel)[.a-zA-z0-9]*");
+    public static final Pattern CAMEL_FILTER_PATTERN = 
Pattern.compile("(?i)Camel[.a-zA-z0-9]*");
 
     /**
-     * A filter pattern for keys starting with <tt>Camel</tt>, <tt>camel</tt>, 
or <tt>org.apache.camel.</tt>
+     * A filter pattern for keys starting with <tt>Camel</tt>, or 
<tt>camel</tt>.
      */
-    public static final String[] CAMEL_FILTER_STARTS_WITH = new String[] { 
"Camel", "camel", "org.apache.camel." };
+    public static final String[] CAMEL_FILTER_STARTS_WITH = new String[] { 
"Camel", "camel" };
 
     @Metadata(javaType = "java.lang.String",
               description = "Sets the in direction filter set. The in 
direction is referred to copying headers from an external message to a Camel 
message."
@@ -75,10 +75,10 @@ public class DefaultHeaderFilterStrategy implements 
HeaderFilterStrategy {
     @Metadata(label = "advanced", defaultValue = "false",
               description = "Whether to allow null values. By default a header 
is skipped if its value is null. Setting this to true will preserve the 
header.")
     private boolean allowNullValues;
-    @Metadata(label = "advanced", defaultValue = "false",
+    @Metadata(label = "advanced", defaultValue = "true",
               description = "Sets the caseInsensitive property which is a 
boolean to determine whether header names should be case insensitive"
                             + " when checking it with the filter set. It does 
not affect filtering using regular expression pattern.")
-    private boolean caseInsensitive;
+    private boolean caseInsensitive = true;
     @Metadata(label = "advanced", defaultValue = "true",
               description = "Sets what to do when a pattern or filter set is 
matched."
                             + " When set to true, a match will filter out the 
header. This is the default value for backwards compatibility."
@@ -375,8 +375,7 @@ public class DefaultHeaderFilterStrategy implements 
HeaderFilterStrategy {
     private boolean tryPattern(String headerName, String lower, Pattern 
pattern) {
         // optimize if its the default pattern as we know the pattern is to 
check for keys starting with Camel
         if (pattern == CAMEL_FILTER_PATTERN) {
-            boolean match = headerName.startsWith("Camel") || 
headerName.startsWith("camel")
-                    || headerName.startsWith("org.apache.camel.");
+            boolean match = headerName.startsWith("Camel") || 
headerName.startsWith("camel");
             if (match) {
                 return true;
             }
@@ -384,7 +383,7 @@ public class DefaultHeaderFilterStrategy implements 
HeaderFilterStrategy {
                 if (lower == null) {
                     lower = headerName.toLowerCase();
                 }
-                match = lower.startsWith("camel") || 
lower.startsWith("org.apache.camel.");
+                match = lower.startsWith("camel");
                 if (match) {
                     return true;
                 }
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
index fb5a7ad5fa5..77e6a52dd44 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc
@@ -24,6 +24,15 @@ The `ExchangeHelper.copyResults` has been improved to also 
copy over exchange va
 Removed unused `Johnzon` in `org.apache.camel.model.dataformat.JsonLibrary` 
enum as `camel-johnzon` is not supported
 in Camel v4. This removal also means `johnzon` was removed from XSD and YAML 
DSL schemas.
 
+==== Header Filter Strategy
+
+The default `HeaderFilterStrategy` has changed to be case-insensitive by 
default. This ensures that headers sent over transports
+will be filtered also if they use different cases such as `camelKey` and 
`CAMELKEY`, `camelkey` would all be considered
+the same key and filtered.
+
+The default `HeaderFilterStrategy` has also removed filtering of keys starting 
with the legacy Camel v1 syntax `org.apache.camel.`.
+Camel v2 onwards are using the `Camel...` key standard.
+
 ==== Propagating variables in EIPs in seda/kamelet components
 
 The kamelet and seda component and EIPs such as Split, Multicast, Recipient 
List, Enrich, PollEnrich, Loop (copy mode)

Reply via email to