Skip to content

Conversation

@predic8
Copy link
Member

@predic8 predic8 commented Jan 17, 2026

Summary by CodeRabbit

  • Refactor

    • Replaced legacy header-filtering with a modular header filter and interceptor offering configurable include/exclude rules and an updated configuration API.
  • New Features

    • Added a tutorial demonstrating header removal using the new header-filter.
  • Tests

    • Added unit tests for rule matching and filter behavior; adapted existing tests to the new API and adjusted one expected error status from 500 to 400.
  • Chores

    • Added/updated Apache 2.0 license headers in multiple test files.

✏️ Tip: You can customize this high-level summary in your review settings.

…arate classes, improve maintainability, and enhance test coverage
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

📝 Walkthrough

Walkthrough

Replaces the legacy header-filter interceptor with a new headerfilter package: adds HeaderFilterRule, HeaderFilter, and a new HeaderFilterInterceptor; removes the old monolithic interceptor class; updates tests, imports, and adds new unit tests and a tutorial YAML.

Changes

Cohort / File(s) Summary
Removed Legacy Interceptor
core/src/main/java/com/predic8/membrane/core/interceptor/HeaderFilterInterceptor.java
Deleted old interceptor and its nested Rule/Include/Exclude types and Action enum; removed lifecycle methods.
New HeaderFilter Package - Core Classes
core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterRule.java, core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilter.java, core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterInterceptor.java
Adds HeaderFilterRule (pattern + action, keep/remove factories, case-insensitive regex), HeaderFilter (applies rules over header fields and executes actions), and HeaderFilterInterceptor delegating filtering in request/response/abort hooks.
Updated Tests for New API
core/src/test/java/com/predic8/membrane/core/interceptor/HeaderFilterInterceptorTest.java
Refactors tests to use headerfilter package, static keep()/remove() factories, and adjusted method signatures/usages.
New Unit Tests
core/src/test/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterRuleTest.java, core/src/test/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterTest.java
Adds tests validating rule matching, case-insensitivity, repeated fields, and removal/keep semantics.
Tutorial / Examples
distribution/tutorials/advanced/80-Removing-HTTP-Headers.yaml
Adds tutorial YAML demonstrating headerFilter usage and example rules.
Import / Test Hygiene & License Headers
core/src/test/.../APIProxySpringConfigurationTest.java, multiple distribution/src/test/... files, annot/src/main/.../YamlParsingUtils.java
Replaces wildcard imports with targeted headerfilter imports; adds Apache-2.0 license headers in several test files; minor test expectation tweak (500→400) in one distribution test.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant HFI as HeaderFilterInterceptor
  participant HF as HeaderFilter
  participant Backend as BackendServer

  Client->>HFI: send request (Exchange/Message)
  HFI->>HF: filter request headers (apply rules)
  HF->>HF: iterate header fields, match rules, remove/keep
  HF-->>HFI: filtered headers
  HFI->>Backend: forward filtered request
  Backend-->>HFI: response
  HFI->>HF: filter response headers
  HF->>HF: iterate header fields, match rules, remove/keep
  HF-->>HFI: filtered response
  HFI-->>Client: return response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

7.x

Suggested reviewers

  • rrayst
  • christiangoerdes

Poem

🐰 I hopped through patterns, soft and keen,
Kept a header here, nibbled one unseen.
Regex whiskers twitching, rules in tow,
I pruned the fields and watched them go.
Tiny paws, tidy trail — off I go! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Headerfilter Syntax for YAML' accurately reflects the primary changes: a comprehensive refactoring of the header filtering interceptor with new public API classes (HeaderFilter, HeaderFilterRule, HeaderFilterInterceptor) that support YAML configuration, plus a new advanced tutorial demonstrating the YAML syntax for removing HTTP headers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@predic8
Copy link
Member Author

predic8 commented Jan 17, 2026

XML is not working at this stage. When we agree on the change we must add the modifications for XML.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In
`@core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterInterceptor.java`:
- Around line 79-86: handleAbort currently calls filter(exchange.getResponse())
which will NPE if the response is missing; update handleAbort in
HeaderFilterInterceptor to guard against a null response by checking
exchange.getResponse() != null before calling filter(Message), or alternatively
make the private filter(Message msg) null-tolerant by returning early when msg
is null; reference the handleAbort method and the private filter(Message) method
(and the internal filter field used inside it) when applying the change.

In
`@core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterRule.java`:
- Around line 41-45: The XML text-content binding was lost after adding
`@MCAttribute` on setPattern causing pattern to be null and p uninitialized (NPE
in matches()); update HeaderFilterRule so setPattern(String pattern) accepts
and/or reads text-content as well as the attribute (or restore former
text-binding), and add a null/empty guard that throws an informative exception
(fail fast) if pattern is missing; ensure the compiled Pattern field p is always
initialized when pattern is set and apply the same fix to the other
pattern-compiling setter referenced in the class (the second setter that also
assigns p/matches usage).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilter.java`:
- Around line 47-48: setRules currently assigns the incoming List directly which
allows a null to be stored and will cause an NPE in HeaderFilter.filter; change
HeaderFilter.setRules to guard against a null argument by replacing a null with
an empty, immutable list (e.g. Collections.emptyList()) or by validating and
throwing IllegalArgumentException, ensuring this.rules is never null when used
by HeaderFilter.filter.
♻️ Duplicate comments (1)
core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterRule.java (1)

20-27: Guard against unset pattern to avoid runtime NPE.
Line 20 allows an action-only rule, but Line 52 dereferences p unconditionally. If a rule is built without setPattern, matches() will throw. Consider either enforcing a non-null pattern or using a default match-all pattern.

🛠️ Proposed fix
 `@MCTextContent`
 public void setPattern(String pattern) {
-    this.pattern = pattern;
-    p = Pattern.compile(pattern, CASE_INSENSITIVE);
+    if (pattern == null || pattern.isBlank())
+        throw new IllegalArgumentException("HeaderFilterRule pattern must be set.");
+    this.pattern = pattern;
+    p = Pattern.compile(pattern, CASE_INSENSITIVE);
 }
 
 public boolean matches(String header) {
-    return p.matcher(header).matches();
+    if (p == null)
+        throw new IllegalStateException("HeaderFilterRule pattern must be configured before use.");
+    return p.matcher(header).matches();
 }

Also applies to: 41-52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants