-
Notifications
You must be signed in to change notification settings - Fork 150
Headerfilter Syntax for YAML #2628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…arate classes, improve maintainability, and enhance test coverage
…or` final for immutability
📝 WalkthroughWalkthroughReplaces the legacy header-filter interceptor with a new headerfilter package: adds Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ 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. Comment |
|
XML is not working at this stage. When we agree on the change we must add the modifications for XML. |
There was a problem hiding this 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).
...rc/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterInterceptor.java
Show resolved
Hide resolved
core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilterRule.java
Outdated
Show resolved
Hide resolved
…rios, and simplify action references
There was a problem hiding this 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 dereferencespunconditionally. If a rule is built withoutsetPattern,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
core/src/main/java/com/predic8/membrane/core/interceptor/headerfilter/HeaderFilter.java
Show resolved
Hide resolved
… files, update test cases for HeaderFilterRule and error handling
… with `headerFilter`
Summary by CodeRabbit
Refactor
New Features
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.