You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/02/14 11:41:57 UTC

[camel] 02/02: CAMEL-16202: camel-core - Optimize DefaultHeaderFilterStrategy filtering

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

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

commit e463fcb3efc985e3d3cd4deb997401c50c327503
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 14 12:40:19 2021 +0100

    CAMEL-16202: camel-core - Optimize DefaultHeaderFilterStrategy filtering
---
 .../camel/support/DefaultHeaderFilterStrategy.java | 23 +++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

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 eff21be..fa1ad2a 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
@@ -275,8 +275,22 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
             filter = inFilter;
         }
 
-        if (pattern != null && pattern.matcher(headerName).matches()) {
-            return filterOnMatch;
+        String lower = null;
+        if (pattern != null) {
+            // 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("org.apache.camel.") || headerName.startsWith("Camel");
+                if (!match) {
+                    // the default filter is case insensitive so check for lower case starting match
+                    lower = headerName.toLowerCase(Locale.ENGLISH);
+                    match = lower.startsWith("org.apache.camel.") || lower.startsWith("camel");
+                }
+                if (match) {
+                    return filterOnMatch;
+                }
+            } else if (pattern.matcher(headerName).matches()) {
+                return filterOnMatch;
+            }
         }
 
         if (filter != null) {
@@ -287,7 +301,10 @@ public class DefaultHeaderFilterStrategy implements HeaderFilterStrategy {
                     }
                 }
             } else if (isLowerCase()) {
-                if (filter.contains(headerName.toLowerCase(Locale.ENGLISH))) {
+                if (lower == null) {
+                    lower = headerName.toLowerCase(Locale.ENGLISH);
+                }
+                if (filter.contains(lower)) {
                     return filterOnMatch;
                 }
             } else {